Java Runtime freeMemory() and totalMemory() method

public class Test {
  public static void main(String[] args) {
	  Runtime runtime=Runtime.getRuntime();  
	  System.out.println("Total Memory: "+runtime.totalMemory());  
	  System.out.println("Free Memory: "+runtime.freeMemory());  
	    
	  for(int i=0;i<15000;i++){  
	   new Test();  
	  }  
	  System.out.println("Free Memory, after creating 15000 instance: "+runtime.freeMemory());  
	  System.gc();  
	  System.out.println("Free Memory after gc(): "+runtime.freeMemory());  
  }
}  
Please follow and like us:
Content Protection by DMCA.com