Skip to content

Possible memory leak with class Error #4910

@sgeraud

Description

@sgeraud

The following works well, but replacing line new BigObj() by new Error() results in a very large heap snapshot, even if heapdump.writeSnapshot(); triggers garbage collection.

var async = require("async");
var heapdump = require("heapdump");

var seq = [];
for (var i = 0; i < 50000; i++) {
    seq[i] = i;
}

function BigObj() {
    this.message = "hello";
    this.x = [];
    for (var i = 0; i < 1000; ++i) {
        this.x.push("mlkj");
    }
}

heapdump.writeSnapshot();
async.mapSeries(seq, function (x, cb) {
    var err = new BigObj();
    // var err = new Error();
    setTimeout(function () {
        err.message;
        cb(null);
    }, 0);
}, function () {
    heapdump.writeSnapshot();
    process.exit();
});

Snapshots for BigObj:

-rw-r--r--  1 sgeraud  staff   1,7M 27 jan 16:32 heapdump-195670438.615838.heapsnapshot
-rw-r--r--  1 sgeraud  staff   6,4M 27 jan 16:33 heapdump-195739533.54126.heapsnapshot

Snapshots for Error:

-rw-r--r--  1 sgeraud  staff   1,7M 27 jan 16:34 heapdump-195804014.440544.heapsnapshot
-rw-r--r--  1 sgeraud  staff    66M 27 jan 16:35 heapdump-195873113.196591.heapsnapshot

Observed with node v0.12.7 and node v5.5.0 on Mac OS X 10.11.2
and node v5.41. on Ubuntu 14.04.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    memoryIssues and PRs related to the memory management or memory footprint.questionIssues that look for answers.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions