• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Garbage Collection

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain me how should i develop the technique to solve GC questions:
Also at any line in the following code, is a single object eligible for garbage collection n why?

public class Island {
Island n ;
public static void main(String [] args) {
Island i2 = new Island();
Island i3 = new Island();
Island i4 = new Island();

i2.n = i3;
i3.n = i4;
i4.n = i2;

i2 = null;
i3 = null;
i4 = null;
}
}
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact, the key point for garbage collection question is to
remember the following rule :

"An object is eligible for garbage collection when no live thread can access it"

(taken from Sierra&Bates preparation book, thanks to them).
Also remember that you can only say when an object is eligible for garbage
collection, not when the garbage collector run.

With this rule in hand, you can solve the above problem, which is an
example of "island of isolation".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic