Created
November 7, 2012 23:44
-
-
Save pushmatrix/4035423 to your computer and use it in GitHub Desktop.
Testing out whether V8 within Chrome runs garbage collection on global variables (assigned to window)
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
<script> | |
function logMemory() { console.log("Heap use(MB): " + window.performance.memory.usedJSHeapSize / 1000000, ", Total heap size(MB): " + window.performance.memory.totalJSHeapSize / 1000000) }; | |
window.things = {}; | |
things.array = []; | |
function leak() { | |
for(var i = 0; i < 5000000; i++) { | |
things.array.push("test string"); | |
} | |
} | |
logMemory(); | |
leak(); | |
leak(); | |
leak(); | |
leak(); | |
leak(); | |
logMemory(); | |
window.things = null; | |
setTimeout(function() { | |
logMemory(); | |
}, 2500); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This article suggests that
Experimentation in Chrome 23 suggests otherwise. The GC will eventually be run, bringing the heap size back to where it started.