aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC: Islands of Isolation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC: Islands of Isolation" Watch "GC: Islands of Isolation" New topic
Author

GC: Islands of Isolation

Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

hi folks,

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?


Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

Yes that is correct. Just because you set a reference of an object to null does not mean the object's member references will be set to null.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

What about this:


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
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

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
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

Oh ok. Now I get it.

All clear John, thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC: Islands of Isolation
 
Similar Threads
Garbage Collection
Isolating a Reference
islands of isolation
Isolating a reference
Garbage Collection Question