Skip to content

Instantly share code, notes, and snippets.

@darahayes
Last active February 9, 2018 23:50
Show Gist options
  • Save darahayes/8802d7372905c6ec03fa6e3ca8d7ae76 to your computer and use it in GitHub Desktop.
Save darahayes/8802d7372905c6ec03fa6e3ca8d7ae76 to your computer and use it in GitHub Desktop.
const http = require('http');
const memwatch = require('memwatch-next');
const heapdump = require('heapdump');
var server = http.createServer((req, res) => {
for (var i=0; i<1000; i++) {
server.on('request', function leakyfunc() {});
}
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
server.setMaxListeners(0);
console.log('Server running at http://127.0.0.1:1337/. Process PID: ', process.pid);
memwatch.on('leak', (info) => {
console.error('Memory leak detected:\n', info);
heapdump.writeSnapshot((err, filename) => {
if (err) console.error(err);
else console.error('Wrote snapshot: ' + filename);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment