Garbage Collection listener
Execute the callback function when garbage collection happens
function logGarbageCollection(checkFrequency, cb) {
var t
allocNew()
checkObj()
function allocNew() {
t = new WeakRef({})
}
function checkObj() {
if(t.deref() != undefined) {
setTimeout(checkObj, checkFrequency)
} else {
cb()
allocNew()
checkObj()
}
}
}
logGarbageCollection(100, function() {
console.log('GC happened')
})