looks like that an instance variable is assigned, it is actually assigning a class variable, aka, static variable. So b1 is still referenced in Alpha.b1, remember, even though a2 gets collected, b1 still won't be collected since you don't need to instantiate an instance to assign a class variable.
So only a1 is not referenced by anybody and becomes dangling reference, and therefore only 1 object will be garbage collected. In real code, the form in
is discouraged since it is confusing to the readers and sometimes coders themselves.
Joined: Oct 31, 2009
Thank you George. I have debugged the code and now it makes sense.
Joined: Apr 08, 2009
You are always welcome.
Max Campa wrote:Thank you George. I have debugged the code and now it makes sense.