v8是否对单个对象的堆分配有限制?
a = new Array(1024*1024*102)
在节点命令行上失败
FATAL ERROR: JS Allocation failed - process out of memory
此外,当作为脚本运行时,这会失败并出现相同的错误
node --expose-gc --nouse-idle-notification --max-old-space-size=8192
FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory
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();
}
}
Run Code Online (Sandbox Code Playgroud)
最后输出:
{ rss: 1009557504, heapTotal: 993408824, heapUsed: 964980592 }
然而,
var a = [];
while(1) {
var …Run Code Online (Sandbox Code Playgroud)