Release java memory for OS at runtime.

前端 未结 5 1804
-上瘾入骨i
-上瘾入骨i 2020-12-07 01:58

Suppose I have a Swings Java Application, I set the min Heap is 64MB and max Heap 2GB, when the user start the application, the log in screen will be displayed, at this time

5条回答
  •  心在旅途
    2020-12-07 02:22

    I have posted my test results over there. Basically, MaxHeapFreeRatio is not respected by every GC implementation, and, to make it worse, it seems to be necessary that there is enough heap activity in order to trigger it in a timely manner, ie. could be that you require 2 full GC runs to actually release the memory to the OS. And if you have a burst memory footprint of X GB, then you probably have to allocate 1 or 2 times of that amount in order to trigger the heap downsize. Or you call System.gc() manually.

    If performance is not an issue, and memory footprint is all that counts, try:

    -XX:UseSerialGC -Xms16M -Xminf=5 -Xmaxf=10
    

提交回复
热议问题