Following is part of very big logic, function track is just for simplification. Track loads object from database and stores in cache.
var cache = []; function newObject(a){ var b = {}; b.tracker = a; cache.push(b); } var t = {}; track(t); track(t); track(t); track(t); ... cache.length = 0; track(t); track(t); track(t); track(t); .... cache.length = 0; After clearing cache, does it cause memory leak because b.tracker is holding reference to t? For clarification, tracker t does not store any reference to any object created.
Do I need following method?
for(var i=0;i<cache.length;i++){ cache[i].tracker = null; } cache.length = 0; Or JavaScript engine is smart enough to remove all instance of b because no body references b anymore?