1

To do some benchmarking, I tried to create a huge array. The code was simple:

var hugeArray = [];
for (var i = 0; i < 2*1000*1000*100; i ++) {
    hugeArray.push(Math.ceil(Math.random()*100))
}
console.log(hugeArray.length);

After I run it with 200 million elements, I get FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory. With 20 million elements, this works well, so I assume I need to change some setting.

I am using MacOS with 8 GB of RAM, if that helps.

Alberto Rivera
  • 3,652
  • 3
  • 19
  • 33

1 Answers1

7

V8's heap size is limited to 1 GB..So if you want to increase it run following

node --max-old-space-size=8000 yourScript.js

Hope this helps.

Mykola Borysyuk
  • 3,373
  • 1
  • 18
  • 24