How to free or increase available JVM runtime memory in java with Example
2779 Views
Runtime.gc() method
Increasing free memory of JVM runtime using gc() method of Runtime Object.
Runtime runtime = new Runtime();
runtime.gc();
GCFreeMemoryExample
public class GCFreeMemoryExample {
public static void main(String args[]) throws Exception {
Runtime runtime = Runtime.getRuntime();
System.out.println("Presently available free memory on JVM: "+runtime.freeMemory()+" bytes.");
//Run to increcase available memory size of JVM
runtime.gc();
System.out.println("After gc method call free memory on JVM: "+runtime.freeMemory()+" bytes.");
}
}
Output
Presently available free memory on JVM: 15487000 bytes.
After gc method call free memory on JVM: 15952240 bytes.