Knowledge Walls
John Peter
Pune, Maharashtra, India
How to free or increase available JVM runtime memory in java with Example
2797 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.
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details