当我执行JUnit测试时,我得到了这个错误消息:

java.lang.OutOfMemoryError: GC overhead limit exceeded

我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?


当前回答

如果您确定程序中没有内存泄漏,请尝试:

增加堆的大小,例如-Xmx1g。 启用并发低暂停收集器-XX:+UseConcMarkSweepGC。 在可能的情况下重用现有对象以节省内存。

如果需要,可以通过在命令行中添加-XX:-UseGCOverheadLimit选项来禁用限制检查。

其他回答

要在IntelliJ IDEA中增加堆大小,请遵循以下说明。这对我很管用。

对于Windows用户,

转到安装IDE的位置并搜索以下内容。

idea64.exe.vmoptions

编辑该文件并添加以下内容。

-Xms512m
-Xmx2024m
-XX:MaxPermSize=700m
-XX:ReservedCodeCacheSize=480m

就是这样!!

引用Oracle的文章“Java SE 6 HotSpot[tm]虚拟机垃圾收集调优”:

Excessive GC Time and OutOfMemoryError The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line.

编辑:看起来有人打字比我快:)

解决: 只需添加 org.gradle.jvmargs = -Xmx1024m 在 gradle.properties 如果它不存在,那就创造它。

重启MacBook帮我解决了这个问题。

在Netbeans中,设计最大堆大小可能会有所帮助。执行命令Run =>设置项目配置=>自定义。在弹出窗口的运行中,进入虚拟机选项,填写-Xms2048m -Xmx2048m。它可以解决堆大小的问题。