This discussion is archived
5 Replies Latest reply: Dec 21, 2010 12:45 PM by 824658 RSS

why is -XX:MaxHeapFreeRatio not working for me?

824658 Newbie
Currently Being Moderated
My application sees occasional spikes in memory usage. After these rare spikes, I want to return unused heap memory back to OS. So I am playing with following JVM options:

-XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40

However what I am seeing is that even though more than 40% heap is free, heap size is not shrinking and memory is not going back to OS. This is what I see with XX:printGCDetails:

[GC [DefNew: 2149K->122K(2304K), 0.0012210 secs] 18851K->16824K(31228K), 0.0012870 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew: 2234K->25K(2304K), 0.0009530 secs] 18936K->16736K(31228K), 0.0010060 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

From above output: heap utlization = 16736/31228 = 54% (approx)
Which means 46% heap is free and should shrink since we specified MaxHeapFreeRatio=40, but its not shrinking.

Overall I am seeing my application using less memory than when I don't use MaxHeapFreeRatio, but why are these numbers not matching?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points