• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generational garbage collection.

 
Grigory O. Ptashko
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I'm trying to understand how generational garbage collection works in Java. I just want to understand what processes are held by a VM regarding generational garbage collection.

As far as I understood all the heap is devided into 2 regions. The one called "Nursery", that holds freshly created objects and the one that holds "old objects". Generational garbage collection implies that GC doesn't run in "nursery" region of objects until it's full. If this is right then here are my questions:

1) If an object gets old (not unreferenced but just old) when is it moved from the "nursery" to "old" region? At the time when the GC decides to clean up the "nursery" area?

2) How often and specificly when does the GC clean "old objects" region?

3) How a VM knows if the "nursery" region is full? I mean isn't it the same expensive process as the GC itself (I believe it is NOT)?

4) Do I ever have to call System.gc() and System.runFinalization() in my application, I mean I just don't understand what are those calls for?


Thank you.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The generational collector is used in Sun JVM and possibly some others but not in all JVMs. It is even possible to create a JVM without any GC (causing OutOfMemmoryError when all available space is allocated).

2) It is determined by some algorithms in JVM and its parameters.
3) The objects in nursery are allocated in one continuous area so when it reached the end of it, it is full. GC always defragments the nursery so there are never any "holes".
4) You don't have to call them. The methods are only usesful for performance tuning but tuning JVM parameters is usally better method.
 
Virag Saksena
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of your questions are answered in
Sun's GC description
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!