I have a Springboot application with Mule running inside a docker container as a micro service. It takes about 700MB even when it is idle. It is noticed that JVM has allocated heap of 380 MB which is max heap provided using -Xmx
parameter. Though max heap is allocated, the micro service only use about 50 MB when idle. The question is how to released unused memory back from JVM.
It seems that reducing MaxHeapFreeRatio we can ask JVM to shrink when there is more free memory ratio. However MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40
did not make much difference and JVM did not release memory. But when I use -Xmn
with above two parameters JVM releases heap memory as expected. See below image for example scenario.
Java version 8
-Xmn100M -XX:+PrintGCDetails -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -Xmx384M
- Why does MinHeapFreeRatio and MaxHeapFreeRatio does not work as expected?
- If above parameters are fine what are the consequences of
-Xmn
and what is the value of it should be? - What are other solutions in order to achieve the task of releasing memory back from JVM?