Thursday, April 12, 2007

How JVM performs Garbage Collection?

One of the most frequently asked questions during interviews and it seeks a precise and clear understanding of the concept. Whenever a reference to an object on heap lies dangling or no longer in use by an active program then it becomes eligible for being garbage collected by JVM.JVM specifications do not force any specific kind of garbage collection algorithm though there are several algorithms like reference counting,tracing,compacting,copying,generational etc. in place.It is very important that garbage collection should be efficient and non interfering in execution of Java programs.There is a trade off between ease of implementation versus better performance while implementing garbage collection feature for a JVM.

Since J2SE1.2 JVM incorporated different algorithms and that are combined using generational collection.This mechanism can be compared with a container or bucket kind of thing, where new object or infant/young objects are kept another as tenured and the third is permanent. The objects lying in young container are more often checked and quick to go in garbage state while this phenomenon decreases with tenure. So when objects are old enough or survive enough to be part of tenure zone then they become less likely to be garbage collected.The JVM specific classes and method objects are part of permanent zone and are never garbage collected.

So it is quite likely that non reachable object still remains out of bound of gabage collection due to how much time an object has survived for as mentioned above, how much heap space JVM is consuming for its running,if it is low then whole process of garbage collection slows down.

More you would like to explore here.

0 comments :

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker