Java Garbage Collection Process(GC)
Garbage Collection(GC) is a process of removing free objects or unused objects from heap memory. So that the memory can be reused by another objects. JVM is internally using GC technique called Garbage-First(G1) to handle this task for new JVM(JDK7 Update 4).
There is provision given in Java API to call GC from code by calling System.gc() or Runtime.gc() method. GC is handling destructor’s job in Java. There is no destructor supported in Java because JVM is handling the memory management job.
Previous versions of Java uses Concurrent Mark and Sweep(CMS) but it is being replaced by Garbage-First(G1) technique.
Garbage-First(G1) is highly recommended by Server JVM and Multi Processor System with large memory(6GB or higher). G1 offers best performance of JVM compare to previous version of GC techniques. This would be the long terms plan as replacement of CMS.