Hi all, is there a way to know when an object will be disposed by GC?
My object (call it A) write some variables in a global array-object, so when the object will be garbaged its own variable will stay in the global array-object, taking up memory.
ps. i have numerous objects A and i prefer to not call "manually" a method to free my global array-object.
This is my situation:
var global_array=[];
function A(x){
global_array.push({who:"A", what:x, id:A.instance++});
this.x=x;
}
A.instance=0;
A.prototype.useIt=function(){
return this.x*2;
}
//will be created an A object and will be garbaged after use by GC
function test(){
var a=new A(10);
var y=a.useIt();
}
test();
//i will never use <a> object again, but global_array hold {who:"A", what:10, id:0)}
DO NOT WANT
A.prototype.dispose=function(){
// free global_array at the correct index
}
Thanks.