Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

GC: Islands of Isolation

 
Ranch Hand
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Royston Monteiro
Ranch Hand
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok. Now I get it.

All clear John, thanks
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic