title: Java Heap Space - How does -Xmx work exactly?
body: <p>I have encountered the infamous <strong>OutOfMemoryException</strong> in my application and instead of simply increasing the amount of Heap Space available I tried to look into what the problem was, just in case, there was some sort of leak from my application. </p>
  
  <p>I added the JVM parameter <strong>-XX:+HeapDumpOnOutOfMemoryError</strong> which creates a Heap Dump when the OutOfMemory Error is encountered. I then analysed the dump file produced with different profiling tools. I then started playing around with the -Xmx parameter and observing patterns. </p>
  
  <p>What puzzled me is the following. Why is it that on analyzing the dump I found that the total size of all objects was much less than the total that I set using the -Xmx parameter?
  For example, say I set the -Xmx to '2048m'. When I analyzed the dump file I found a total of 400Mb of objects on the Heap. I was expecting to find 2GB. Am I missing something? </p>