gpt4 book ai didi

intellij-idea - 为什么 Intellij 关闭项目后不释放内存?

转载 作者:行者123 更新时间:2023-12-02 01:31:55 39 4
gpt4 key购买 nike

我打开了三个项目。其中之一——Spark——非常大。关闭 Spark 后,内存使用情况没有差异 - 正如 os/x 事件监视器所报告的那样。注意:所有项目都在同一个 Intellij 实例中打开。

enter image description here

实际上它使用的内存刚刚超过 4GB。我现在只有两个项目处于开放状态。如果我关闭 Intellij 并再次启动,这两个项目仅占用 1.5GB。

那么..如何“鼓励”Intellij 释放它正在使用的内存呢?它运行得非常非常慢(例如跟不上我的打字速度)

更新我刚刚关闭了剩余两个项目中较大的一个。 仍然内存使用量没有减少。剩下的项目是一个单个 python 文件。所以Intellij此时应该在512Meg下使用!

最佳答案

根据@PeterGromov 的回答,似乎很难恢复内存。此外@KevinKrumwiede提到了XX:MaxHeapFreeRatio,这似乎是一个途径。

以下是一些与 Does GC release back memory to OS? 稍远的想法

The HotSpot JVM does release memory back to the OS, but does so reluctantly.

You can make it more aggressive by setting -XX:GCTimeRatio=19 -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=30 which will allow it to spend more CPU time on collecting and constrain the amount of allocated-but-unused heap memory after a GC cycle.

Additionally with Java 9 -XX:-ShrinkHeapInSteps option can be be used to apply the shrinking caused by the previous two options more aggressively. Relevant OpenJDK bug.

Do note that shrinking ability and behavior depends on the chosen garbage collector. For example G1 only gained the ability to yield back unused chunks in the middle of the heap with jdk8u20.

So if heap shrinking is needed it should be tested for a particular JVM version and GC configuration.

来自How to free memory in Java?

To extend upon the answer and comment by Yiannis Xanthopoulos and Hot Licks (sorry, I cannot comment yet!), you can set VM options like this example:

-XX:+UseG1GC -XX:MinHeapFreeRatio=15 -XX:MaxHeapFreeRatio=30 In my jdk 7 this will then release unused VM memory if more than 30% of the heap becomes free after GC when the VM is idle. You will probably need to tune these parameters.

While I didn't see it emphasized in the link below, note that some garbage collectors may not obey these parameters and by default java may pick one of these for you, should you happen to have more than one core (hence the UseG1GC argument above).

我将向 IJ 添加 -XX:MaxHeapFreeRatio 并报告它是否有帮助。

我们的应用程序目前仅在 Java7 上运行,因此上述第一种方法不可行 - 但仍有希望,因为我们的应用程序很快就会迁移到 jdk8。

关于intellij-idea - 为什么 Intellij 关闭项目后不释放内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39940311/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com