admin管理员组文章数量:1201805
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);
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?
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);
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?
- My first guess was that the first size was slightly less than the biggest 32-bit integer, and the second slightly bigger, but there's one too few zeros for that to be the problem. – Pointy Commented May 29, 2015 at 3:17
- Interestingly, I actually can't recreate this in v0.10. v0.11 segfaults. – fny Commented May 29, 2015 at 4:29
- 2 Perhaps relevant: Node.js heap memory limit for single object – jfriend00 Commented May 29, 2015 at 4:32
- 1 Sounds like it was introduced in 0.11.15 and it's still open. – Val Commented May 29, 2015 at 5:36
- There is something fishy here, why would 300 000 000 not give you the same warning? Does the console print the correct length when you use 300 000 000? – Frank Bryce Commented Jul 8, 2015 at 14:09
3 Answers
Reset to default 11V8'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.
Compiling Typescript to ES2017+ might solve this issue.
Sources:
NodeJS memory growth - Memory leak in (system)?
https://github.com/express-validator/express-validator/issues/824
There is a limit of memory.64bit Machines can use about 1.6gb.This is the limit of V8 compiler. this links maybe can help you
Configuring v8's memory management to be smart for a node.js process
https://groups.google.com/forum/#!topic/nodejs/BQ5dSm8lITQ
本文标签: javascriptnodeinvalid array lengthStack Overflow
版权声明:本文标题:javascript - node - invalid array length - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738579353a2101067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论