Home Java Javascript-array Get Usage Memory Example
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Get Usage Memory Example

Advertisement
In this Tutorial we make you a code that helps you in understanding Get Usage Memory.

Get Usage Memory Example

     

In this Tutorial we make you a code that helps you in understanding Get Usage Memory. The class Memory Usage include the main method, that contain the following method - 

!)Runtime.getRuntime( ).total Memory ( )  -  This method return you the total amount of memory that your java program allocate inside JVM.

2)Runtime.getRuntime( ).free Memory ( )  -  This method return you the total amount of free memory available that your program allocate

The variable usage memory is calculated by subtracting total memory and free memory. Finally the println print the Total, Free and Usage memory.

MemoryUsage.java
public class MemoryUsage {

  public static void main(String args[]) {

  long totalMemory = Runtime.getRuntime().totalMemory();
  long freeMemory = Runtime.getRuntime().freeMemory();
  
  long usageMemory = totalMemory - freeMemory;
  
  System.out.println("Total Memory : " + totalMemory);
  System.out.println("Free Memory  : " + freeMemory);
  System.out.println("Usage Memory : " + usageMemory);
  }
}

Output :
Total Memory : 5177344
Free Memory  : 4978792
Usage Memory : 198552

Download code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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 13, 2008

Ask Questions?    Discuss: Get Usage Memory Example   View All Comments

Post your Comment


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

February 7, 2012


code error.. kindly check po. tnx
DMCA.com