I too made a memory map diagram for the same and I conclude that because of a2.a=null and a1=a3 just one object that is a2 is eligible for garbage collection because as a1 and a3 are still being referenced so they are not eligible . am I understanding it correctly?
Can you please tell more specifically which object is eligible for garbage collection and why because by diagram I am able to understand that one object is there which is eligible for it but which one . I guessed is a2. Please clear it.
posted 11 years ago
On line 10
A a2=new A(new A(null)); the object which is created by calling "new A(null)" does not have any reference. So this object will be garbage collected.