Sebanti Sanyal wrote:Inside method go(),two objects are created. f3 refers tothe object originally referred by f2. That particular object has a member variable f,which again refers to the object initially referenced by f1. Therefore, none of the two are eligible for GC at line 18. If we also had f3=null;, the two objects would still had referenced each other but none of them could be accessed externally and hence eligible for GC.
In main(),one object is created on which go() was invoked.That object was created on the go,and there is no reference associated with it.Hence, it is definitely eligible for GC at line 8.The two objects created inside go() were accessible only with a local variable f3,which does not live anymore after go() returns. These two can also be garbage collected at line 8.
Thank your for the explanation it is very clear.
If I remove base=null, what will be the result? I'm a little confused because base is static. Thanks