Java Network

How to explicitly invoke Garbage Collection in Java

Java runtime system performs the garbage collection asynchronously depending on the available resources. When there are no more references to an object, the object is finalized and when the Garbage Collections starts these finalized objects gets collected.

Sometimes you need to run garbage collector explicitly just before some memory intensive task. You can run garbage collector by this statement.

System.gc();

Finalization process can also be invoked explicitly using the following statement. After the execution of this statement all the objects those are without reference, are finalized.