Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I know the amount of Free memory

Status
Not open for further replies.

aryajur

Programmer
Jul 2, 2003
45
US
I need to know the amount of free memory remaining on a system. Can this be done in Java. If it can be done please tell me how? Are there any classes??
 
The following code will print the total, free and used amount of memory :
Code:
  public Test3() {
  }

  private void doIt() {
      long totalMemory = Runtime.getRuntime().totalMemory();
      long freeMemory = Runtime.getRuntime().freeMemory();
      long usedMemory = totalMemory - freeMemory;
      System.out.println("TotalMemory = " + totalMemory);
      System.out.println("FreeMemory = " + freeMemory);
      System.out.println("Used Memory = " + usedMemory);
  }

  public static void main(String[] args) {
    Test3 example = new Test3();
    example.doIt();
  }

}
You might also want to check :
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top