• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Garbage Collection  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!