I think 2 is correct.
- First you create 3 Objects and their 3 references a b c:
A a = new A();
A b = new A();
A c = new A();
- than you link the objects:
a.aob = b;
b.aob = a;
c.aob = a.aob;
After this one Object is referenced by a and b.aob.
one Object is referenced by b and a.aob
one Object is referenced by c
Than they try to get you confused:
- 2 Objects are created.
- The First gets a reference to the Second
- After this d gets the result of this operation (The result of the assignment is the assigned Object- so the 2nd Object is reffered)
- the First Object is available for the gc
A d = new A().aob = new A();
Now they set
c = b;
So the Object referenced by c is now ready for the GC (it now also references the Object that is referenced by b and a.aob)
This is senceless:
c.aob = null;
Because there is another reference to the Object (a)