CodesJava

Easy learning with example program codes

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:
Posted in Java   

Core Java Tutorial



Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki