Java program to perform garbage collection

This program performs garbage collection. Free memory in java virtual machine is printed and then garbage collection is done using gc method of RunTime class, freeMemory method returns amount of free memory in jvm, getRunTime method is used to get reference of current RunTime object. 

public static void main(String[] args) {
      
 Runtime rm=Runtime.getRuntime();
 System.out.println(rm.freeMemory());
        rm.gc();
        System.out.println(rm.freeMemory());
       }