Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Timer.unref() memory leak #8364

Closed
Closed
@patriksimek

Description

@patriksimek

Consider this code:

// script.js

var formatBytes = function(bytes) {
    var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)))
    return (bytes / Math.pow(1024, i)).toFixed(1) + sizes[i]
};

setInterval(function() {
    var mem = process.memoryUsage();
    console.log('rss:', formatBytes(mem.rss), 'heapTotal:', formatBytes(mem.heapTotal), 'heapUsed:', formatBytes(mem.heapUsed));
}, 1000);

var method = function() {
    var tmr = setTimeout(function() { method() }, 0);
    if (process.argv[2] == '--unref') tmr.unref();
};

method();

To reproduce the issue, start the script with node script.js --unref. Heap snapshot taken after few minutes of running the script:

snimek obrazovky 2014-09-13 v 13 17 02

There are thousands of Timers leaking memory:

snimek obrazovky 2014-09-13 v 13 17 34

And this is a heap snapshot taken from the version without unref (node script.js):

snimek obrazovky 2014-09-13 v 13 17 55

This is a hourly report from our app that uses unref frequently:

snimek obrazovky 2014-09-13 v 13 25 04

OSX 10.9.4 & Debian 7.6
Node 0.10.31

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions