Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java5 -XX:MaxHeapFreeRatio=45 doesn't release heap even when more than 45% of the heap is free

Tags:

java

memory

I have a java application with the arguments below but the heap is not getting reclaimed even when the total free space is greater than 45% (can see via visual VM). Is there any reason that the JVM wouldnt free that heap space? The same settings work as expected in Java6. Running Java5 runtime and compile time

java -jar -Xmx1024m -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=45 -XX:+HeapDumpOnOutOfMemoryError <myjarname>
like image 409
Joe Avatar asked Jan 18 '23 06:01

Joe


2 Answers

We believe we have found an answer to the question. The systems we are running are server class machines with multiple CPUs the JRE was detecting the multiple CPUs and setting the GC to use parallel instead of serial GC which is not compatible with the XX:MaxHeapFreeRatio setting.

like image 88
Joe Avatar answered Mar 02 '23 01:03

Joe


The only GC that gives the memory back my system is the G1GC -XX:+UseG1GC

like image 26
Frank Avatar answered Mar 02 '23 00:03

Frank