title: Why does my Java heap dump show only half the heap?
body: <p>I'm intentionally adding items to a data structure until Java throws an <code>OutOfMemoryError</code>, and grabbing a heap dump using <code>-XX:+HeapDumpOnOutOfMemoryError</code>.  I'm using <code>-Xmx100M</code>, so I expected the heap dump would show nearly 100MB of live objects, but instead it shows only 46MB.</p>
  
  <p>Why would Java throw OOM with a 100MB heap if there are only 46MB of live objects?</p>
  
  <p>(I realize there's a good chance I haven't given enough information to answer this question, but I'm not sure what's relevant.  Happy to add more info as needed.)</p>
  
  <p>EDIT:  The end of the <code>-verbose:gc</code> output:</p>
  
  <pre><code> [Full GC (Ergonomics) [PSYoungGen: 1056K-&gt;64K(2560K)] [ParOldGen: 7116K-&gt;7116K(7168K)] 8173K-&gt;7180K(9728K), [Metaspace: 5981K-&gt;5981K(1056768K)], 0.0071141 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
   [Full GC (Allocation Failure) [PSYoungGen: 64K-&gt;0K(2560K)] [ParOldGen: 7116K-&gt;7075K(7168K)] 7180K-&gt;7075K(9728K), [Metaspace: 5981K-&gt;5974K(1056768K)], 0.0190392 secs] [Times: user=0.02 sys=0.00, real=0.02 secs] 
   java.lang.OutOfMemoryError: Java heap space
  </code></pre>