Skip to content

Instantly share code, notes, and snippets.

@robey
Created June 27, 2015 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robey/de6717a41734d802c864 to your computer and use it in GitHub Desktop.
Save robey/de6717a41734d802c864 to your computer and use it in GitHub Desktop.
test case for memory leak while recursing a while-loop in bluebird
var Promise = require('bluebird');
function stream() {
var active = true;
var count = 0;
var loop = function () {
if (!active) return;
count++;
if (count % 100000 === 0) console.log((process.memoryUsage().heapUsed / (1024*1024)).toFixed(2), "mb", count / 100000);
return get().then(function (v) {
return loop();
}).catch(function (error) {
active = false;
});
};
return loop();
}
function get() {
return Promise.resolve(false).then(function () { return false; });
}
stream();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment