Skip to content

Instantly share code, notes, and snippets.

@einaros
Created March 30, 2012 13:32
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 einaros/77654c1d91fd4ff8a7fa to your computer and use it in GitHub Desktop.
Save einaros/77654c1d91fd4ff8a7fa to your computer and use it in GitHub Desktop.
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