In the above code, I was wondering..If i2 is set to null, doesnt all the instance variables of i2(and hence i2.n) also get set to null? Why does K&B(pg 249, 250) say that i2.n still exists and "points" to i3?
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
In this case, after setting c1 = null, the c1.story reference should still be on the stack(like in the previous example), referring to the Short object. But the answer says that at this stage, even the Short object is eligible for garbage collection
This is correct as well. You must however notice that there is not island of isolation here
Reference -> Short
After setting the reference to null there is not way to reach the Short. So the JVM GCs it. In case of the island however the JVM thinks the objects can be reached since they point to each other in a circle. The JVM does not figure that these objects dont have an external reference through which they can be reached, even though they can reach each other through their internal references.
Does that make it clear ? Or have I managed to confuse you more