Skip to content

Instantly share code, notes, and snippets.

@mdlavin
Created May 24, 2016 16:55
Show Gist options
  • Save mdlavin/334338eb801bd3243679db89c219c7ac to your computer and use it in GitHub Desktop.
Save mdlavin/334338eb801bd3243679db89c219c7ac to your computer and use it in GitHub Desktop.
An example application to demonstrate a small buffer/closure leak from zlib
const memwatch = require('memwatch-next');
const _ = require('lodash');
const zlib = require('./lib/zlib');
function writeLeakDiff(diff) {
const closures = _.filter(diff.change.details, {what: 'Closure'});
console.log('Closure changes', closures);
const buffers = _.filter(diff.change.details, {what: 'Uint8Array'});
console.log('Uint8Array changes', buffers);
}
var before = new memwatch.HeapDiff();
var deflator = zlib.createDeflateRaw();
var done = new Promise( (resolve) => {
const input = '.................................';
deflator.write(input);
deflator.flush( () => {
resolve();
});
});
done.then( () => {
setImmediate( () => {
var diff = before.end();
writeLeakDiff(diff);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment