I just encounter a strange problem:
var a:ClassA = new ClassA;
var b:ClassA = a;
The program keeps running sometime, the a = null, b = null.
The program is a complex one, I am sure that no part will touch a, and b. My question is, will the runtime(garbage collector) to collect the memory of “a” and then assign a and b to null?
I am confused, thanks!
The garbage collector will reclaim the memory that this instance of
ClassAoccupies, only once there is no longer a reference to it. As long asaORbreferences that memory location, the instance will remain. If these are local variables, then the instance will be picked up by the GC at some point after the function/method exits. If those are instance variables then they will remain until after the defining class’ instance is collected.