posted 14 years ago
c3 is a reference - it is never eligible for garbage collection.
on line 8, an object is created, and c1 is made to refer to it.
on line 9, an object is created, and c2 is made to refer to it.
on line 10, we call the go() method of c1, and pass in the reference to which the c2 reference points.
on line 3, the c1 reference variable now points to the same object as c2.
on line 4, the c2 reference variable now points to null, but c2 still points to the object.
on line 5, we return the value in c2, which is null...
so c3 points to null (back to line 10).
on line 11, c1 is made to point to null. Therefore object created on line 3 has no active references and is eligible for gc.
when we get to line 12, c2 still points to the object it originally did, so that object is NOT eligible for gc.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors