Skip to content

Memory leak in gzip #6139

@antelle

Description

@antelle
  • Version: v5.7.1
  • Platform: Darwin 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
  • Subsystem: zlib

Here's the code with a memory leak:

var b = new Buffer(10000000);
for (var i = 0; i < b.length; i++) {
    b[i] = Math.random();
}
for (var i = 0; i < 1000; i++) {
    console.log('#' + i, mem());
    var out = new stream.PassThrough();
    var gzip = zlib.createGzip();
    gzip.pipe(out);
    gzip.write(b);
    gzip.end();
}

setInterval(function() { console.log(mem()); }, 1000);

function mem() {
    global.gc();
    return Math.round(process.memoryUsage().rss / 1024 / 1024) + 'M';
}

Looks like the code is ok, gzip streams are closed. The same happens with file streams, not only PassThrough. After compression is finished, memory usage is about 100MB and it doesn't decrease anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    memoryIssues and PRs related to the memory management or memory footprint.zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions