Get free memory, max memory and total size of JVM runtime memory in java with Example
2923 Views
RuntimeJavaExample
public class RuntimeJavaExample{
public static void main(String args[]) throws Exception {
Runtime runtime = Runtime.getRuntime();
System.out.println("Present free memory on JVM: "+runtime.freeMemory()+" bytes.");
//Run to increcase free memory of JVM
runtime.gc();
System.out.println("After gc method call free memory on JVM: "+runtime.freeMemory()+" bytes.");
System.out.println("Max memory of JVM: "+runtime.maxMemory()+" bytes.");
System.out.println("Total available memory of JVM: "+runtime.totalMemory()+" bytes.");
}
}
Output
Present free memory on JVM: 15487000 bytes.
After gc method call free memory on JVM: 15952240 bytes.
Max memory of JVM: 1037959168 bytes.
Total available memory of JVM: 16318464 bytes.