Skip to content

Instantly share code, notes, and snippets.

@wearhere
Last active August 29, 2015 14:26
Show Gist options
  • Save wearhere/5765be04d9f1bd50a3fa to your computer and use it in GitHub Desktop.
Save wearhere/5765be04d9f1bd50a3fa to your computer and use it in GitHub Desktop.
Simple harness to exercise a memory leak in Node. Copied from https://github.com/alexeypetrushin/synchronize/pull/32, credit @d3m3vilurr.
var immediately = function(cb) {
sync.fiber(function() {
setImmediate(sync.defer());
sync.await();
}, cb);
};
function test(m, cb) {
if (m-- === 0) return cb();
immediately(function(err) {
if (err) return cb(err);
if (m % 1000 === 0) {
console.log(m + ": " + JSON.stringify(process.memoryUsage()));
}
test(m, cb);
});
}
test(100000000, function(err) {
if (err) throw err;
console.log("done");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment