How to solve java.lang.OutOfMemoryError: GC overhead limit exceeded error in android studio

50,364

Solution 1

I solved this issue by adding

dexOptions { 
          incremental true 
          javaMaxHeapSize "4g" 
} 

to the android closure in build.gradle file. Found this answer in

OutOfMemoryError: GC overhead limit exceeded

Solution 2

Add this to your "gradle.properties" file:

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

EDIT: an updated answer based on my experience:

On Android Studio, choose Help -> Edit custom VM options , and then set the max memory the IDE is allowed to use. For example, if you want 5GB, use this:

-Xmx5g

Save the file, close all windows of the IDE (make sure it has no processes) and then restart the IDE.


EDIT: Android Studio now has RAM configuration in its settings. Go to "help"->"change memory settings".

Solution 3

Find the Memory Settings

  1. Cmd + Shift + A on Mac (Ctrl + Shift + A on Windows) or click on Help
  2. Type "Memory Settings"

under Preferences/ Settings and increase the IDE Heap Size and/ or the Daemon Heap Size to your satisfaction enter image description here

Solution 4

I had the same issue too - mine was for a different reason. I was working on backing up some files and accidentally dropped a big file in the resource folder. It was close to 40MB.

Once this file was removed, the error was gone.

Solution 5

Add this line in your build.gradle

dexOptions
         {
               incremental false
               javaMaxHeapSize "2048M" 
               preDexLibraries = false
         }
Share:
50,364
user3008777
Author by

user3008777

Updated on July 21, 2022

Comments

  • user3008777
    user3008777 almost 2 years

    I am using android studio 1.0 RC for 64 bit linux.

    When I run my application I am getting

    "java.lang.OutOfMemoryError: GC overhead limit exceeded"
    

    When I searched on how to solve this error I got solutions like add:

    • -XX:-UseGCOverheadLimit to studio.vmoptions or studio64.vmoptions
    • -Xmx2000m to studio.vmoptions or studio64.vmoptions etc.

    These did not work for me.

    Please help. Thanks in advance