Home Java Java-get-example Java get Heap Size
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java get Heap Size

Advertisement
In this section, we are going to illustrates you how to obtain the heap size. The heap is the area in the memory used for memory storage during the runtime of the program.

Java get Heap Size

     

In this section, we are going to illustrates you how to obtain the heap size. The heap is the area in the memory used for memory storage during the runtime of the program. 

getRuntime()- This method returns the runtime object of the current Java application.

totalMemory() - This method returns the total amount of memory in the JVM.

 

 

Here is the code of GetHeapSize.java

public class GetHeapSize
{
  public static void main(String[]args){
  long heapSize = Runtime.getRuntime().totalMemory();
  System.out.println("Heap Size= "+heapSize);
  }
}

Output will be displayed as:

Download Source Code

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 1, 2008

Ask Questions?    Discuss: Java get Heap Size   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com