java.lang.OutOfMemoryError:在 Android 1.4 上超出了 GC 开销限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32133013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:04:09  来源:igfitidea点击:

java.lang.OutOfMemoryError: GC overhead limit exceeded on Android 1.4

javaandroidgarbage-collection

提问by Amay Diam

I get an java.lang.OutOfMemoryError: GC overhead limit exceededwhen run gradle on Android 1.4 ... these are my depedencies :

在 Android 1.4 上运行 gradle 时,我收到一个java.lang.OutOfMemoryError: GC 开销限制超出了......这些是我的依赖:

dependencies {
    compile project(':android-crop')
    compile project(':RTEditor-Toolbar')

        compile files('libs/apache-mime4j-0.6.jar')
        compile files('libs/httpmime-4.1.3.jar')
    /*    compile files('libs/httpcore-4.4.1.jar')*/
    compile files('libs/jetbrains-annotations.jar')
    compile files('libs/pinchzoom.jar')
    compile files('libs/gcm.jar')
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    //three party library
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.vinaysshenoy:mugen:1.0.1'
    compile 'com.github.clans:fab:1.5.5'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.curioustechizen.android-ago:library:1.3.0'
    compile 'com.squareup.okio:okio:1.5.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;
    }

How can this be fixed?

如何解决这个问题?

采纳答案by King of Masses

Add this to your android closure(build gradle):

将此添加到您的 android 闭包中(构建 gradle):

 dexOptions {
        javaMaxHeapSize "4g"
 }

This will solve your problem. Still, if you face problem see the following link

这将解决您的问题。不过,如果您遇到问题,请参阅以下链接

GC overhead limit exceeded error

GC 开销限制超出错误

回答by greg8188

When JVM/Dalvik spends more than 98% doing GC and only 2% or less of the heap size is recovered the “java.lang.OutOfMemoryError: GC overhead limit exceeded” is thrown.

当 JVM/Dalvik 花费超过 98% 的时间进行 GC 并且只恢复了 2% 或更少的堆大小时,会抛出“ java.lang.OutOfMemoryError: GC 开销限制超出”。

The solution is to extend heap space or use profiling tools/memory dump analyzers and try to find the cause of the problem.

解决方案是扩展堆空间或使用分析工具/内存转储分析器并尝试找到问题的原因。

回答by android developer

This is what I suggest:

这是我的建议:

Add this to your "gradle.properties" file:

将此添加到您的“gradle.properties”文件中:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError

Also, read this article. You might be able to make the building a bit faster, by adding a combination of those:

另外,请阅读这篇文章。您可以通过添加以下组合来加快构建速度:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

回答by Md Ayub Ali Sarker

My test were failing in gradle version 5.2.1 "GC overhead limit exceeded java.lang.OutOfMemoryError: GC overhead limit exceeded". I solved by adding maxHeapSizein build.gradle like below:

我的测试在 5.2.1 版 gradle 中失败了“GC 开销限制超出 java.lang.OutOfMemoryError: GC 开销限制超出”。我通过在 build.gradle 中添加maxHeapSize来解决,如下所示:

 test {
        maxHeapSize = "4g"
    }

回答by Abhishek Dhyani

This worked for me !! Just add the following lines into "gradle.properties" file

这对我有用!!只需将以下行添加到“gradle.properties”文件中

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

回答by Kyo Kurosagi

In my case, OutOfMemoryError is come from this error. Starting a Gradle Daemon, 1 busy and 6 stopped Daemons could not be reused, use --status for details

就我而言, OutOfMemoryError 来自此错误。启动 Gradle 守护进程,1 个忙碌和 6 个停止的守护进程无法重用,使用 --status 了解详细信息

To solve this. I use ./gradlew --stopor ./gradle --stop. If still not solved which mean the gradle process is lock (this happen after OutOfMemoryError).

为了解决这个问题。我使用./gradlew --stop./gradle --stop。如果仍然没有解决,这意味着 gradle 进程被锁定(这发生在 OutOfMemoryError 之后)。

Go to /users/[username]/.gradle/daemon(hidden) folder.

转到/users/[username]/.gradle/daemon(隐藏)文件夹。

You will see each built gradle version folder like 3.2 3.3 4.0.1 4.1 4.10.1 4.10.2 4.4 4.6 5.4.1 5.5

您将看到每个构建的 gradle 版本文件夹,例如 3.2 3.3 4.0.1 4.1 4.10.1 4.10.2 4.4 4.6 5.4.1 5.5

Go into these folders and remove the file named

进入这些文件夹并删除名为

registry.bin

registry.bin.lock

注册表.bin

注册表.bin.lock

For me, I remove all these folders.

对我来说,我删除了所有这些文件夹。

Then rebuild you app. Should be work now.

然后重建你的应用程序。现在应该上班了。

回答by Yudi karma

just go to prefrence or settings -> memori settings -> and setup your alocated memory

只需转到偏好或设置 -> 内存设置 -> 并设置您的分配内存

android studio 3.5

安卓工作室 3.5