Created
June 15, 2013 11:55
-
-
Save mateuszkocz/5787882 to your computer and use it in GitHub Desktop.
JavaScript debugging function that logs app's memory usage (heap size). Source: Martin Wells (https://gist.github.com/martinwells/2968021)
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
var lastUsedHeap = 0; // remember the heap size | |
function checkMemory() | |
{ | |
// check if the heap size is this cycle is LESS than what we had last | |
// cycle; if so, then the garbage collector has kicked in | |
if (window.performance.memory.usedJSHeapSize < lastUsedHeap) | |
console.log('Garbage collected!'); | |
lastUsedHeap = window.performance.memory.usedJSHeapSize; | |
} | |
setTimeout(checkMemory, 100); // test 10 times per second |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment