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

Description
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:

There are thousands of Timers leaking memory:

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

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

OSX 10.9.4 & Debian 7.6
Node 0.10.31