What is garbage collection?

Hi,

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

Thanks
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 http://www.roseindia.net/answers/viewqa/Java-Interview-Questions/1892-garbage-collector.html
Thanks

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
System.gc()

may be used to call it explicitly.

Thanks









Related Tutorials/Questions & Answers:
Advertisements