How to Get Free Memory of JVM in Java


Here we will learn how to get amount of free memory in the Java Virtual Machine(JVM) using freeMemory method of java Runtime class.

Source Code

package com.beginner.examples;


public class FreeMemoryExample {

    public static void main(String[] args){
    	
    	Runtime run = Runtime.getRuntime();
    	
    	//get freeMemory
    	long memory = run.freeMemory();
		 
		System.out.println(memory + " bytes free in JVM.");
    }
    
}

Output:

126930104 bytes free in JVM.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments