Deepak Kumar
What is garbage collection?
2 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners

Tell me about garbage collection. How garbage collection works in java?

View Answers

October 5, 2010 at 2:17 PM

<b>Garbage Collection in Java</b>

In Java when program executes the JVM creates the object of the Java classes which is to be executed. In this process these objects are stored into memory. When these objects are not need the JVM process removes these objects and then reclaims the memory. This process of finding the unused Java objects and then freeing objects which is no longer is in use is called the Garbage Collection.
The Garbage collection process is automatic and programmer can?t free the un-used objects. Only JVM automatically runs the Garbage collection process.
The Garbage collector is responsible for running the Garbage collection process in Java.
Check the garbage collection code at

October 5, 2010 at 2:20 PM

Java programmer can also instruct the Garbage collection for Garbage collection. But Garbage collector will finally decide weather to call Garbage collection process or not.

Following method

may be used to call it explicitly.