Node.js单个对象的堆内存限制 [英] Node.js heap memory limit for single object
问题描述
v8是否对单个对象的堆分配有限制?
Does v8 have limits on the heap allocations for single objects?
a =新数组(1024 * 1024 * 102)
在节点命令行上失败
致命错误: JS分配失败 - 处理内存不足
此外,当作为脚本运行时,此失败并出现相同的错误
Also, this fails with the same error when run as a script
node --expose-gc --nouse-idle-notification --max-old-space-size = 8192
致命错误:CALL_AND_RETRY_0分配失败 - 处理内存不足
var util = require('util');
o = {};
while(1) {
o["hahahahahaha" + String(ctr)] = ctr;
ctr++;
if (ctr % 100000 === 0) {
console.log(util.inspect(process.memoryUsage()));
if (ctr % 10000000 === 0) gc();
}
}
最后输出:
{rss:1009557504,heapTotal:993408824,heapUsed:964980592}
但是,
var a = [];
while(1) {
var o = {};
o["hahahahahaha" + String(ctr)] = ctr;
a.push(o);
ctr++;
if (ctr % 100000 === 0) {
console.log(ctr);
console.log(util.inspect(process.memoryUsage()));
console.log();
if (ctr % 10000000 === 0) gc();
}
}
很好
{rss:5466140672,heapTotal:1091224368,heapUsed:1070460592}
编辑:
node -v
v0.10.25
uname -a
Linux 3.13.0-24-generic#47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU / Linux
编辑2:
即使这样也行!
似乎v8的限制适用于对象可以拥有的属性数量?
Edit 2: Even this works! It seems that v8's limit applies to number of properties an object can have?
while(1) {
if (!o["hahahahahaha" + String(Math.floor(ctr/1000000))]) {
o["hahahahahaha" + String(Math.floor(ctr/1000000))] = {};
console.log(Object.keys(o))
}
o["hahahahahaha" + String(Math.floor(ctr/1000000))][String(ctr)] = ctr;
ctr++;
if (ctr % 100000 === 0) {
console.log(ctr);
console.log(util.inspect(process.memoryUsage()));
console.log();
if (ctr % 10000000 === 0) gc();
}
}
{rss:2474512384, heapTotal:2466405768,heapUsed:2431583008}
另外,我发现:
https://github.com/v8/v8/blob/master/src/objects.h#L2928
我想知道它是否相关。
推荐答案
它变成了表示字符串,对象和数组的最大大小存在硬限制。
限制是旧垃圾收集器的残余物。
以下是相关的门票:
It turns out that there are hard-limits put on the maximum size of strings, objects and arrays. The limts are a remnant of the old garbage collector. Here is the relevant ticket:
https://code.google.com/p/v8/issues/detail?id=3505
这篇关于Node.js单个对象的堆内存限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!