title: Java 8 full GC and OutOfMemory Java heap space
body: <p>Using <strong>VisualVM</strong> and checking <strong>Tomcat 8.5</strong> catalina.out log I see that <strong><em>almost</em></strong> every time (7 out of 11 times or so) when <strong><em>full GC</em></strong> happens logs show <strong><em>OutOfMemory</em></strong> (at the exact same minute).</p>
  
  <p>With Tomcat <strong><em>parameters</em></strong> that have something to do with memory management: <strong>-Xms3G -Xmx=6G -XX:+UseG1GC -XX:+UseStringDeduplication -XX:MaxHeapFreeRatio=100</strong></p>
  
  <p>At first I thought that it was because of default <strong>-XX:MaxHeapFreeRatio</strong> value which is <strong>70</strong> since I saw that max. heap size (and used heap of course) would drop significantly during <strong><em>full GC</em></strong> - to <em>~10-20%</em>. However adding <strong>XX:MaxHeapFreeRatio=100</strong> did not fix it.</p>
  
  <p>Although this is <strong><em>memory usage graph</em></strong> with <strong><em>different</em></strong> set of <strong><em>JVM parameters</em></strong> (can not get the one with old JVM parameters ATM) it is similar in a way after full GC memory usage <strong><em>grows rapidly</em></strong>, same max. heap size and that max. heap size does not drop.</p>
  
  <p><a href="https://i.stack.imgur.com/5cnR1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5cnR1.jpg" alt="enter image description here"></a></p>
  
  <p><strong><em>Any ideas why this could happen?</em></strong></p>
  
  <p><strong>Update:</strong> I forgot to mention that previously <strong><em>full GC</em></strong> and <strong><em>OutOfMemory</em></strong> would happen when heap size <strong><em>was not even full</em></strong> - ~5GB. Back then not a single time did I see heap reach 6GB.</p>