The gc() method is used to invoke the garbage collector to perform cleanup processing. The gc() is found in System and Runtime classes.
Garbage collection is performed by a daemon thread called Garbage Collector(GC). This thread calls the finalize() method before object is garbage collected. Following is the simple Example of garbage collection in java.
Output