Created
May 24, 2016 16:55
-
-
Save mdlavin/334338eb801bd3243679db89c219c7ac to your computer and use it in GitHub Desktop.
An example application to demonstrate a small buffer/closure leak from zlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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