posted 14 years ago
The reason is even though
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.