title: How to get just free heap size (not together w stack/method mem) in Java?
body: <p>I want to calculate the heap usage for my app. I would like to get a procent value of Heap size <strong>only</strong>.</p>
  
  <p>How do I get the value in code for the current running app?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>There was an upvoted answer that was <strong>NOT complete/correct</strong>. The values returned by those methods include stack and method area too, and I need to monitor only heap size.<br>
  With that code I got HeapError exception when I reached 43%, so I can't use those methods to monitor just heap</p>
  
  <pre><code>Runtime.getRuntime().totalMemory()
  </code></pre>