Knowledge Walls
John Peter
Pune, Maharashtra, India
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.
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