RsD0p9BK
12/30/2015 - 5:45 AM

checkMemory.js

// High-Performance, Garbage-Collector-Friendly Code

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

// http://buildnewgames.com/garbage-collector-friendly-code/