Created
July 5, 2017 17:25
-
-
Save doron2402/72272d3e554603b3414e510d3b787441 to your computer and use it in GitHub Desktop.
Node.js Memory leark
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
'use strict'; | |
const Memwatch = require('memwatch-next'); | |
const Util = require('util'); | |
if (Config.env === 'production') { | |
/** | |
* Check for memory leaks | |
*/ | |
let hd = null; | |
Memwatch.on('leak', (info) => { | |
console.log('memwatch::leak'); | |
console.error(info); | |
if (!hd) { | |
hd = new Memwatch.HeapDiff(); | |
} | |
else { | |
const diff = hd.end(); | |
console.error(Util.inspect(diff, true, null)); | |
trace.report('memwatch::leak', { | |
HeapDiff: hd | |
}); | |
hd = null; | |
} | |
}); | |
Memwatch.on('stats', (stats) => { | |
console.log('memwatch::stats'); | |
console.error(Util.inspect(stats, true, null)); | |
trace.report('memwatch::stats', { | |
Stats: stats | |
}); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment