node - 无效的数组长度
我正在使用节点v0.12.4。
当我用节点运行以下代码--max-old-space-size = 8192 test.js
时,它给出了错误致命错误:数组长度无效分配失败 - 进程内存不足
I'm using node v0.12.4.
When I run the following code with node --max-old-space-size=8192 test.js
it gives me the error FATAL ERROR: invalid array length Allocation failed - process out of memory
var a = new Array(200000000);
console.log(a.length);
但是,如果我将大小更改为300000000,我不会收到任何错误。这里发生了什么?除了还有一些命令行参数 - max-old-space-size
我需要更改吗?
However if I change the size to 300000000 I don't get any error. What's going on here? Is there some command line argument aside from --max-old-space-size
I need to change?
V8的堆大小限制为64位的1 GB和32位机器的512,但缓冲区对象主要存在于堆外。您可以在64位中扩展内存使用最多1.7 GB,在32位计算机中扩展内存使用大约1 GB。
您可以试试这个。
V8's heap size is limited to 1 GB for 64 bit and 512 for 32-bit machine, but Buffer objects exist largely outside the heap. you can expand the memory use up to 1.7 GB in 64-bit and ~1 GB in 32-bit machine. You can try this.
--max-old-space-size=3000 --trace-gc-verbose
您可以打印跟踪以了解内存使用情况。
you can print the trace to know about the memory use.