OutOfMemoryError: GC overhead limit exceeded android

China☆狼群 提交于 2020-01-07 03:48:29

问题


In android studio 1.5.1 just by moving the source code from one system to another and Even though the clean build is successful but while the code is run I am getting this kind of error

java.lang.OutOfMemoryError: GC overhead limit exceeded Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 3

I added the below code in app.gradle also:

dexOptions {
        javaMaxHeapSize "4g"
}

回答1:


GC overhead limit exceeded means that your app occupied all the heap and garbage collector cannot clean enough space to run the program.

So, there is too much necessary data in memory or memory leak (i.e. references which can be accessed from app root but no longer needed) exists in your application - only further app profiling can give you more details




回答2:


The detail message "GC overhead limit exceeded" indicates that the garbage collector is running all the time and Java program is making very slow progress. After a garbage collection, if the Java process is spending more than approximately 98% of its time doing garbage collection and if it is recovering less than 2% of the heap and has been doing so far the last 5 (compile time constant) consecutive garbage collections, then a java.lang.OutOfMemoryError is thrown. This exception is typically thrown because the amount of live data barely fits into the Java heap having little free space for new allocations. Action: Increase the heap size. The java.lang.OutOfMemoryError exception for GC Overhead limit exceeded can be turned off with the command line flag -XX:-UseGCOverheadLimit.

This was taken from Oracle Java Documentation




回答3:


You can increase your allocated memory for the app by adding

android:largeHeap="true"

to your manifest file and see if it solves your problem. But you should look for memory leaks in your app because the OutOfMemoryError is usually a consequence of bad memory management.



来源:https://stackoverflow.com/questions/36131909/outofmemoryerror-gc-overhead-limit-exceeded-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!