How to get just free heap size (not together w stack/method mem) in Java?

Posted by Pentium10 on Stack Overflow See other posts from Stack Overflow or by Pentium10
Published on 2010-05-21T18:38:04Z Indexed on 2010/05/21 20:20 UTC
Read the original article Hit count: 137

Filed under:
|

I want to calculate the heap usage for my app. I would like to get a procent value of Heap size only.

How do I get the value in code for the current running app?

EDIT

The upvoted answer is NOT complete/correct. The values returned by those methods include stack and method area too, and I need to monitor only heap size.
With that code I got HeapError exception when I reached 43%, so I can't use those methods to monitor just heap.

© Stack Overflow or respective owner

Related posts about java

Related posts about heap