<p>I have a problem with the Garbage Collector of my application, I am working in a GCP environment with Kubernetes and BigTable as a data source.</p>
<p>Upon receiving loads, the application does not free up memory space and fills up until k8s restarts the POD. I use a profiler to see the behavior of the JVM and this is the result.</p>
<p>In the &quot;Old Gen&quot; pool it is seen that the memory is full but it never frees the space and it fills up until restarting and starting again.</p>
<p><a href="https://i.stack.imgur.com/dQxtr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dQxtr.png" alt="Old Gen" /></a></p>
<p>In the pool &quot;Eden Space&quot; it is seen that while it is filling, the space is freed and never reaches the limit.</p>
<p><a href="https://i.stack.imgur.com/TIUJQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TIUJQ.png" alt="Eden Space" /></a></p>
<p>This is the JVM configuration when creating the docker image to deploy it in k8s.</p>
<pre><code>java
-XX:+UnlockExperimentalVMOptions
-XX:+UseG1GC
-XX:+UseCGroupMemoryLimitForHeap
-XX:+AlwaysPreTouch
-XX:ParallelGCThreads=5
-XX:GCTimeRatio=4
-XX:MaxGCPauseMillis=100
-XX:MinHeapFreeRatio=30
-XX:MaxHeapFreeRatio=30
-Xms512m
-Xmx4608m
</code></pre>
<p>This same configuration is applied in another application that makes REST calls and has never had memory filling problems as in this case.</p>
<p>Java version is 1.8</p>
<p>Thankful for your help.</p>
<p>Grettings.</p>

<p>Firstly, you have to identify the root cause of your problem to proceed further. I would suggest you to collect more information on the topic with -XX:+PrintGCDetails and -XX:+PrintGCTimeStamps. If your hypothesis that &quot;Old Gen&quot; pool is never frees the space is correct (honestly spearking, it's not obvious from the image),  you might apply few tricks to deal with it as such:</p>
<ul>
<li>Directly specify new and old gc sizes via -XX:MaxNewSize, -XX:NewSize, -XX:MaxOldSize, -XX:MaxOldSize to ensure that there is enough space for old generation</li>
<li>Gather more logs via -XX:+PrintGCDetails and -XX:+PrintGCTimeStamps to see if any issue happens due to over utilizing of one of the generations</li>
<li>Try to increase survivor space ratio via -XX:SurvivorRatio to expedite collection of the old generation objects</li>
</ul>
