Saturday, July 9, 2011

What is Garbage Collector in Java?

Garbage collector is an important component of the JVM. It's responsible to reclaim the memory from objects which are no longer in use. Thus reclaimed memory is made available for new objects.

Any object which is no longer in use is marked or made eligible for garbage collection.

The garbage collector component runs as a low priority demon thread inside the JVM.

A programmer may request the JVM to run garbage collector by calling System.gc() or Runtime.gc().

The garbage collector is automatically detects when JVM detects low memory.

During the process of garbage collection, the garbage collector component ensures that no object who's reference count is greater than zero is claimed.

There is no stack or queue order of garbage collection. i.e., the objects are garbage collected as per the memory location and convenience of the garbage collector.

No comments :

Post a Comment