Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var MB = 1024 * 1024;
console.log('Initial rss: %d MB', ~~(process.memoryUsage().rss / MB));
(function() {
(function() {
var buffers = [];
(function() {
for (var i = 0; i < 5000; ++i) {
var buf = new Buffer(65536);
buffers.push(buf);
for (var x = 0; x < 65536; ++x) buf[x] = 123;
}
})();
buffers = null;
})();
console.log('After closure has completed, buffer array is unreachable, rss: %d MB', ~~(process.memoryUsage().rss / MB));
gc();
setTimeout(function() {
gc();
console.log('After two gc calls and 5 second delay, rss: %d MB', ~~(process.memoryUsage().rss / MB));
}, 5000);
})();
/* output on node v0.6.14
Initial rss: 9 MB
After closure has completed, buffer array is unreachable, rss: 325 MB
After two gc calls and 5 second delay, rss: 135 MB
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.