当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当我执行JUnit测试时,我得到了这个错误消息:
java.lang.OutOfMemoryError: GC overhead limit exceeded
我知道什么是OutOfMemoryError,但是GC开销限制意味着什么?我怎么解决这个问题?
当前回答
我不知道这是否仍然相关,但只是想分享对我有用的东西。
更新kotlin版本至最新可用版本。https://blog.jetbrains.com/kotlin/category/releases/
做完了。
其他回答
如果您确定程序中没有内存泄漏,请尝试:
增加堆的大小,例如-Xmx1g。 启用并发低暂停收集器-XX:+UseConcMarkSweepGC。 在可能的情况下重用现有对象以节省内存。
如果需要,可以通过在命令行中添加-XX:-UseGCOverheadLimit选项来禁用限制检查。
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
}
}
//...
您还可以通过将此添加到gradle中来增加内存分配和堆大小。属性文件:
org . gradle。jvmargs = -Xmx2048M -XX: MaxHeapSize \ = 32g
它不需要2048M和32g,你想要多大就有多大。
下面的方法对我很有效。只需添加以下片段:
android {
compileSdkVersion 25
buildToolsVersion '25.0.1'
defaultConfig {
applicationId "yourpackage"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "4g"
}
}
这条消息意味着由于某种原因,垃圾收集器花费了过多的时间(默认情况下占进程所有CPU时间的98%),并且在每次运行中回收的内存非常少(默认情况下占堆时间的2%)。
这实际上意味着您的程序停止执行任何进度,并且一直忙于只运行垃圾收集。
为了防止应用程序占用CPU时间而不做任何事情,JVM抛出这个错误,以便您有机会诊断问题。
我很少看到这种情况发生的情况是,一些代码在已经非常受内存限制的环境中创建了大量临时对象和大量弱引用对象。
请查看Java GC调优指南,该指南可用于各种Java版本,其中包含关于此特定问题的部分:
Java 11调优指南中有针对不同垃圾收集器的过量GC的专门章节: 用于并联集热器 用于同步标记扫描(CMS)收集器 对于垃圾优先(G1)收集器,没有提到这种特定的错误条件。 Java 8调优指南及其过量GC部分 Java 6调优指南及其过量GC部分。