Win a copy of Spring in Action (5th edition) 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!