Heapspeicherlimit von Node.js für ein einzelnes Objekt

Gibt es in Version 8 Beschränkungen für die Heapzuweisung für einzelne Objekte?

a = new Array(1024*1024*102)

schlägt in der Knotenbefehlszeile mit fehl

FATAL ERROR: JS Allocation failed - process out of memory

Außerdem schlägt dies mit demselben Fehler fehl, wenn es als Skript ausgeführt wird

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();
    }
}

Letzte Ausgabe:

{ rss: 1009557504, heapTotal: 993408824, heapUsed: 964980592 }

Jedoch,

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();
    }
}

ist in Ordnung

{ rss: 5466140672, heapTotal: 1091224368, heapUsed: 1070460592 }

Bearbeiten:

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

Edit 2: Auch das funktioniert! Es scheint, dass die Grenze von v8 für die Anzahl der Eigenschaften gilt, die ein Objekt haben kann.

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 }

Ich habe auch folgendes gefunden:https://github.com/v8/v8/blob/master/src/objects.h#L2928

Ich frage mich, ob es relevant ist.

Antworten auf die Frage(1)

Ihre Antwort auf die Frage