当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当前回答
I'm working in Android Studio and encountered this error when trying to generate a signed APK for release. I was able to build and test a debug APK with no problem, but as soon as I wanted to build a release APK, the build process would run for minutes on end and then finally terminate with the "Error java.lang.OutOfMemoryError: GC overhead limit exceeded". I increased the heap sizes for both the VM and the Android DEX compiler, but the problem persisted. Finally, after many hours and mugs of coffee it turned out that the problem was in my app-level 'build.gradle' file - I had the 'minifyEnabled' parameter for the release build type set to 'false', consequently running Proguard stuffs on code that hasn't been through the code-shrinking' process (see https://developer.android.com/studio/build/shrink-code.html). I changed the 'minifyEnabled' parameter to 'true' and the release build executed like a dream :)
简而言之,我必须改变应用程序级别的“构建”。Gradle文件来自: / /……
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sign_config_release
}
debug {
debuggable true
signingConfig signingConfigs.sign_config_debug
}
}
//...
to
//...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.sign_config_release
}
debug {
debuggable true
signingConfig signingConfigs.sign_config_debug
}
}
//...
其他回答
解决: 只需添加 org.gradle.jvmargs = -Xmx1024m 在 gradle.properties 如果它不存在,那就创造它。
要在IntelliJ IDEA中增加堆大小,请遵循以下说明。这对我很管用。
对于Windows用户,
转到安装IDE的位置并搜索以下内容。
idea64.exe.vmoptions
编辑该文件并添加以下内容。
-Xms512m
-Xmx2024m
-XX:MaxPermSize=700m
-XX:ReservedCodeCacheSize=480m
就是这样!!
您可以尝试通过参考此映像来更改服务器设置,并增加用于处理的内存大小 流程更改以黄色突出显示
你也可以通过打开cmd-> set _java_opts - xmx2g来改变java堆 2g(2gb),这取决于程序的复杂程度
尽量少使用常数变量和临时变量
Java堆大小描述(xms, xmx, xmn)
-Xms size in bytes
Example : java -Xms32m
设置Java堆的初始大小。 默认大小为2097152 (2MB)。 该值必须是1024字节(1KB)的倍数且大于1024字节。 (-server标志将默认大小增加到32M。)
-Xmn size in bytes
Example : java -Xmx2m
设置Eden生成的初始Java堆大小。 默认值为640K。 (-server标志将默认大小增加到2M。)
-Xmx size in bytes
Example : java -Xmx2048m
设置Java堆可以增长到的最大大小。 默认大小为64M。 (-server标志将默认大小增加到128M。) 最大堆限制大约是2 GB (2048MB)。
Java内存参数(xms, xmx, xmn)格式化
在设置Java堆大小时,应该使用字母“m”或“m”表示MB,或使用字母“g”或“g”表示GB来指定内存参数。如果指定“MB”或“GB”,则该设置将不起作用。有效参数是这样的:
-Xms64m或-Xms64m -Xmx1g或-Xmx1g 还可以用2048MB指定2GB吗 另外,确保在指定参数时使用整数。使用-Xmx512m是一个有效的选项,但是-Xmx0.5g会导致错误。
这种推荐对某些人是有帮助的。
根据Java[8]平台,标准版故障处理指南,错误原因:(强调和换行符添加)
[…“GC overhead limit exceeded”表示垃圾收集器一直在运行,Java程序进展非常缓慢。 在垃圾收集之后,如果Java进程花费大约98%的时间进行垃圾收集,如果它回收的堆不到2%,并且到目前为止已经连续进行了5次(编译时间常数)垃圾收集,则抛出Java .lang. outofmemoryerror。[…]
Increase the heap size if current heap is not enough. If you still get this error after increasing heap memory, use memory profiling tools like MAT ( Memory analyzer tool), Visual VM etc and fix memory leaks. Upgrade JDK version to latest version ( 1.8.x) or at least 1.7.x and use G1GC algorithm. . The throughput goal for the G1 GC is 90 percent application time and 10 percent garbage collection time Apart from setting heap memory with -Xms1g -Xmx2g , try -XX:+UseG1GC -XX:G1HeapRegionSize=n -XX:MaxGCPauseMillis=m -XX:ParallelGCThreads=n -XX:ConcGCThreads=n
看看更多关于G1GC的相关问题
G1上的Java 7 (JDK 7)垃圾收集和文档 生产环境中的Java G1垃圾收集 Oracle technetwork关于GC优化的文章