Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js单个对象的堆内存限制_Javascript_Node.js_Memory Management_V8 - Fatal编程技术网

Javascript Node.js单个对象的堆内存限制

Javascript Node.js单个对象的堆内存限制,javascript,node.js,memory-management,v8,Javascript,Node.js,Memory Management,V8,v8对单个对象的堆分配有限制吗 a=新阵列(1024*1024*102) 在节点命令行上失败,原因是 致命错误:JS分配失败-进程内存不足 var util = require('util'); o = {}; while(1) { o["hahahahahaha" + String(ctr)] = ctr; ctr++; if (ctr % 100000 === 0) { console.log(util.inspect(process.memory

v8对单个对象的堆分配有限制吗

a=新阵列(1024*1024*102)

在节点命令行上失败,原因是

致命错误:JS分配失败-进程内存不足

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();
    }
}
此外,当作为脚本运行时,这也会失败,并出现相同的错误

节点--暴露gc--无空闲通知--最大旧空间大小=8192

致命错误:调用和重试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}

编辑:

节点-v

v0.10.25

uname-a

Linux3.13.0-24-generic\47 Ubuntu SMP周五5月2日23:30:00 UTC 2014 x86\u 64 x86\u 64 x86\u 64 GNU/Linux

编辑2: 即使这样也行! 似乎v8的限制适用于对象可以拥有的属性数量

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:243158308}

此外,我发现:


我想知道这是否相关。

事实证明,对字符串、对象和数组的最大大小有严格的限制。 边缘是旧垃圾收集器的残余物。 这是相关的机票:


有没有办法改变这个限制,在我的笔记本电脑上,这个限制非常小,例如
n=33000000
新数组(n)。填充(0)