How Can We Find the Memory Usage of JVM From Java Code ?

We can use memory management related methods provided in java.lang.Runtime class to get the free memory, total memory and maximum heap memory in Java.

By using these methods, you can find out how much of the heap is used and how much heap space still remains.

  • Runtime.freeMemory() returns amount of free memory in bytes.
  • Runtime.totalMemory() returns total memory in bytes.
  • Runtime.maxMemory() returns maximum memory in bytes.


You May Interest

What are the Different Types of Events Provided by Spring Framewo ...

What are the Advantages of Using JSP in Web Architecture ?

What is the Difference Between DOM and SAX Parser in Java ?

Why Collection Interface Doesn’t Extend Cloneable and Serializabl ...

What is a Compile Time Constant in Java ?