Eclipse将堆释放回系统 [英] Eclipse release heap back to system
问题描述
我正在使用Eclipse 3.6和Linux(64位)上的最新Sun Java 6以及大量项目。在某些特殊情况下(例如SVN更新),Eclipse需要最多1 GB的堆。但大多数时候它只需要350 MB。当我启用堆状态面板时,我大部分时间都会看到:
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的878M
350M of 878M
I使用以下设置启动Eclipse:-Xms128m -Xmx1024m
I start Eclipse with these settings: -Xms128m -Xmx1024m
因此大部分时间MB都被浪费了,并且在内存使用率达到峰值时很少使用。我根本不喜欢它,我希望Eclipse将内存释放回系统,所以我可以将它用于其他程序。
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.
当Eclipse需要更多内存时虽然没有足够的可用RAM而不是Linux可以换掉其他正在运行的程序,但我可以忍受。我听说有一个-XX:MaxHeapFreeRatio选项。但我从来没有弄清楚我必须使用什么价值,所以它有效。我试过的价值没有任何价值。
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.
那么我如何告诉Eclipse(或Java)发布未使用的堆?
So how can I tell Eclipse (Or Java) to release unused heap?
推荐答案
找到解决方案。我将Java切换为使用G1垃圾收集器,现在HeapFreeRatio参数按预期工作。所以我在eclipse.ini中使用这些选项:
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
现在当Eclipse在执行复杂操作时会占用超过1 GB的RAM,并在垃圾收集后切换回300 MB,内存实际上会释放回操作系统。
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.
这篇关于Eclipse将堆释放回系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!