See this example: class ObjA {Object b;}
public class
Test {
public static void main(
String args[])
{
ObjA a = new ObjA();
a.b = new Object();
a = null;
}
}
An object is eligible for GC when there is no reference to it. Whether it has reference to other objects is not of concern.
Therefore, object 'a' above has a reference to an Object object, but it is still eligible for GC. (However, the Object object is referenced by 'a' until 'a' is garbage collected).
Now comes the example of circular reference: class Obj1{Obj2 o2;}
class Obj2{Obj1 o1;}
public class Test
{
public static void main(String args[])
{
Obj1 obj1 = new Obj1();
Obj2 obj2 = new Obj2();
obj1.o2 = obj2;
obj2.o1 = obj1;
obj1 = null;
obj2 = null;
}
}
I don't know how Sun developers tackle this issue. You can argue that both of them are still referenced. For me, since there is no outside reference to these two objects, it's no longer possible to munipulate them anymore. Leave these 2 objects in memory just leads to memory leak.
As such, it is logical for the answer to the above question to be FALSE.