Last active
August 29, 2015 14:17
-
-
Save lukehedger/7eda739de2ba253b88b1 to your computer and use it in GitHub Desktop.
Monitor JS garbage collection
This file contains hidden or 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
// run this in Chrome with the --enable-precise-memory-info flag | |
// $ open -a "Google Chrome" --args --enable-precise-memory-info | |
timer = function() { | |
requestAnimationFrame(timer) | |
var heapBefore = window.performance.memory.usedJSHeapSize | |
// run processes here | |
// eg. console.log allocates 2216 bytes, new Object() 56 bytes | |
var heapAfter = window.performance.memory.usedJSHeapSize; | |
// account for 40 bytes allocated to run this function | |
var heapDiff = (heapAfter - heapBefore) - 40; | |
// heapDiff < 0 indicates a garbage collection occurred | |
if (heapDiff < 0) { | |
console.log("gc:", heapDiff); | |
} | |
} | |
requestAnimationFrame(timer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test it out with this pen: http://codepen.io/lukehedger/pen/bNOogj
Resources: