Sachin K Pissay
Sachin K Pissay

Reputation: 693

OutOfMemoryError: GC overhead limit exceeded android

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"
}

Upvotes: 0

Views: 5261

Answers (4)

Dishant Walia
Dishant Walia

Reputation: 711

Updated gradle plugin use R8 process by default to code shrinking. You can try this by adding following lines in gradle.proeprties.

org.gradle.daemon=true

org.gradle.configureondemand=true

org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Upvotes: 3

Stef_ro89
Stef_ro89

Reputation: 81

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.

Upvotes: 0

Cootri
Cootri

Reputation: 3836

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

Upvotes: 2

goncalopinto
goncalopinto

Reputation: 443

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

Upvotes: 2

Related Questions