Created
August 9, 2016 12:00
-
-
Save noam-almog/f9ea4d0923ecb7e94db8618909a5768c to your computer and use it in GitHub Desktop.
memleak
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
function printStats(diff) { | |
// var ignoredTypes = ["Array", "Code", "Object", "String", "Number", "Arguments", "Closure", "Native", "system / Context", "TickObject"]; | |
var ignoredTypes = []; | |
var details = diff.change.details; | |
console.log(diff.change.allocated_nodes); | |
for (var i = 0; i < details.length; i++) { | |
var leakType = details[i].what; | |
if (ignoredTypes.indexOf(leakType) < 0) { | |
if (details[i]['+'] > 0) { | |
console.log("Potential leak: " + leakType + " number of elements: " + details[i]['+']); | |
} | |
} | |
} | |
} | |
function execute(times, func, memdiff) { | |
if (memdiff === false) { | |
console.log("starting"); | |
memwatch.gc(); | |
var startAll = new memwatch.HeapDiff(); | |
} | |
for (var j = 0; j < times; j++) { | |
memwatch.gc(); | |
if (memdiff) { | |
var start = new memwatch.HeapDiff(); | |
} | |
func(); | |
if (memdiff) { | |
memwatch.gc(); | |
var end = start.end(); | |
printStats(end); | |
console.log('------------------------'); | |
} | |
} | |
if (memdiff === false) { | |
var endAll = startAll.end(); | |
printStats(endAll); | |
console.log('------------------------'); | |
console.log("done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment