Force jvm to return internal memory

I occasionally run eclipse tasks that require a very large amount of memory. So jvm while the task runs swallows about 2-3 GB of RAM, this is normal. But as soon as jvm took this memory, it did not release it, and I have a situation where the used memory on the heap is about 200 MB with a total heap size of about 3 GB, and this is really undesirable, as other programs are starving for memory.

I tried the Max/MinHeapFreeRatio to force jvm to reduce the consumption of unused memory. This 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 this does not help, I still have situations where there is a lot of unused memory.

+6
source share
2 answers

Java allocates the maximum heap size when it runs as virtual memory. Since it uses memory, it is allocated as real main memory. It never compresses this size. The only way to free this memory is to exit the program.

Java will reduce memory usage, so many of the pages that it used before can be replaced with a disk, however it can have significant performance if they need them again.

+4
source

I recommend that you read the 2nd of the "stolsvik" comments on this Java / rfe bug - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6498735 . It explains to some extent how the -XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio .

If this does not help, you can try to force the GC several times to find out if this trigger memory is released. And turn on GC logging to find out what it shows.


One possible problem that could interfere with freeing up memory is allocating memory without a JVM heap; for example, for stream stacks, native heaps of code, or direct mapping buffers.

0
source

Source: https://habr.com/ru/post/918658/


All Articles