• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Garbage Collection

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the above program how many objects are eligible for gc.
I think the answer is two as island of isloation exits.But then i have a doubt , h still have live reference h1 so it should not be garbage collected.
I am not got the concept clearly .Kindly explain me.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No , I think answer is one .

infect the other one has two live reference ...
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try giving this a read and see if you can answer your own question.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey ,
I think , that link doesn't have any information about is island of isloation ...
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nay, one is incorrect. Read the link given by Corey and try again, Rathi.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is 0 , And here no funda of island of isloation ...
correct ??
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body put the concept of island of isloation ...

Thanks a lot .
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Can any body put the concept of island of isloation ..."

An "island of isolation" is just a fancy way of saying that one or more objects have no references to them from active parts of an application.

An object is eligible for garbage collection when you no longer have any active references to it. You might still have references to it, but if those references come from objects that have no active references to them, the object is still eligible for garbage collection. Continuing the same methodology as I used in that post, let's look at this example:



So, at line A, how many objects are eligible for garbage collection?

If we look at this using my pictures, we start with this:



Next, we set out t references...



At this point, nothing is eligible for garbage collection because t1 and t2 are both within scope and therefore still active. However, when we do this...



Note that each object still has a reference to it, but those references don't come from an "active" part of the application. There's no longer a way to access either of these objects - we have created an "island of isolation."

So, at point A, there are 2 objects available for garbage collection.
[ March 02, 2005: Message edited by: Corey McGlone ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As an even better idea...how about I work through the example at hand? That probably would have made more sense. Here goes...

First, we instantiate the objects...



Next, we set our internal references...



Finally, we change one more reference...



Notice that the "bottom" object no longer has a direct reference to it, but it is still referenced from an active part of the application (i.e. h.i or h1.i). Therefore, the "bottom" object is not eligible for garbage collection.

As has been stated, the correct answer is 0.
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Corey that was a great explaination.

I then changed the code little bit for my understanding.

now two objects available for garbage collection.Am i right.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramya jp:
Am i right.



Yes.
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Corey
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Corey
 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic