Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force jvm to return native memory [duplicate]

I am running from time to time in eclipse tasks that require very big amount of memory. So jvm while task is running swallows about 2-3gb of RAM, that is ok. But once jvm took that memory it does not release it and I have a situation when used memory in the heap is about 200mb with total heap size about 3gb and that is really unwanted as other programs are starving for memory.

I tried Max/MinHeapFreeRatio parameters to force jvm to reduce consumption of an unused memory. That is my eclipse config.ini file:

-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-vm
c:/Program Files/Java/jdk1.6.0_26/bin/javaw.exe
-showlocation
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Duser.name=Michael Nesterenko
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx4096m
-XX:MinHeapFreeRatio=10
-XX:MaxHeapFreeRatio=30

But that does not help, I still have situations when there are lots of unused memory.

like image 891
michael nesterenko Avatar asked Jun 21 '12 12:06

michael nesterenko


1 Answers

Java allocates the maximum heap size when it starts as virtual memory. As it uses the memory it get allocated as real main memory. It never shrinks this size. The only way to release this memory is for the program to exit.

Java will compact its memory usage so many of the pages it has used before can be swapped to disk, however this can have a significant performance hit if it needs them again.

like image 174
Peter Lawrey Avatar answered Oct 24 '22 06:10

Peter Lawrey