javascript - Why 'delete' doesn't check a property for garbage collector? -
after run code that:
var index = 0; var interval = setinterval(function(){ for(var = 1000; i--;){ var key = "key" + index++; window[key] = index; delete window[key] } }, 100) i see in timeline (google developer tools) memory increases lots of memory in few seconds , when force gc (gc button in timeline) doesn't decreases.
if property can't accessed window , doesn't have other references it, why gc doesn't clean it?
moving comment answer, , adding info other comments:
your loop adds , removed reference, in compiled language might skipped completely. in case happens fast wont see change in memory.
additionally garbage collection not constant process. typically gc run when more memory required. keeps overhead compacted , avoids running gc when wont necessary (the program might end before reach mem limits, why bother collecting before ends)
edit memory see consumed may due interval setup. try similar examples without interval ie. loop uses new locally declared array
Comments
Post a Comment