How to View Total and Free Memory in JAVA

This code snippet allows you to view the total memory and free memory in your console at runtime.

public class MemoryViewing {

public static void main(String[] args) {

System.out.println("Total Memory: " + Runtime.getRuntime().totalMemory());

System.out.println("Free Memory: " + Runtime.getRuntime().freeMemory());

}
}


Runtime is a singleton.

0 comments: