Vivek Raj wrote:However I can see 2 eligible objects, one is object a1 itself and the other is object a1.b2 which also we cannot refer after setting a1 = null.
a1 and a1.b2 are not objects, they are references to objects. An object is only eligible for garbage collection when there are no reachable references to it.
You're right that when a1 is set to null, any object referred to by a1.b2 might also be eligible for garbage collection. So if it isn't, there must be another reference to the same object - can you see what it is ? Have a look at line 12.