Skip to content
Advertisement

Eclipse release heap back to system

I’m using Eclipse 3.6 with latest Sun Java 6 on Linux (64 bit) with a larger number of large projects. In some special circumstances (SVN updates for example) Eclipse needs up to 1 GB heap. But most of the time it only needs 350 MB. When I enable the heap status panel then I see this most of the time:

350M of 878M

I start Eclipse with these settings: -Xms128m -Xmx1024m

So most of the time lots of MB are just wasted and are just used rarely when memory usage peaks for a short time. I don’t like that at all and I want Eclipse to release the memory back to the system, so I can use it for other programs.

When Eclipse needs more memory while there is not enough free RAM than Linux can swap out other running programs, I can live with that. I heard there is a -XX:MaxHeapFreeRatio option. But I never figured out what values I have to use so it works. No value I tried ever made a difference.

So how can I tell Eclipse (Or Java) to release unused heap?

Advertisement

Answer

Found a solution. I switched Java to use the G1 garbage collector and now the HeapFreeRatio parameters works as intended. So I use these options in eclipse.ini:

-XX:+UnlockExperimentalVMOptions
-XX:+UseG1GC
-XX:MinHeapFreeRatio=5
-XX:MaxHeapFreeRatio=25

Now when Eclipse eats up more than 1 GB of RAM for a complicated operation and switched back to 300 MB after Garbage Collection the memory is actually released back to the operating system.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement