0

I'm using a very good desktop machine with very good configuration 8 GB ram and a lot of free space too.

while running the app in my device android studio is giving me this error all the time,

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

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

my studio64.exe.vmoptions file

-Xms256m

-Xmx1024m

-XX:MaxPermSize=350m

-XX:ReservedCodeCacheSize=240m

-XX:+UseConcMarkSweepGC

-XX:SoftRefLRUPolicyMSPerMB=50

-da

-Djna.nosys=true

-Djna.boot.library.path=

-Djna.debug_load=true

-Djna.debug_load.jna=true

-Dsun.io.useCanonCaches=false

-Djava.net.preferIPv4Stack=true

-Didea.paths.selector=AndroidStudio2.2

-Didea.platform.prefix=AndroidStudio

-Didea.jre.check=true

please let me know .. I have disabled instant run feature too.

Jitesh Prajapati
  • 2,533
  • 4
  • 29
  • 51
KarmaCoding
  • 87
  • 3
  • 16
  • change your -Xmx setting from -Xmx1024m to a higher value (e.g. -Xmx2048m). -Xmx specifies the maximum size, in bytes, of the memory allocation pool. – Benjamin Schüller Sep 07 '16 at 06:31
  • Possible duplicate of [Error java.lang.OutOfMemoryError: GC overhead limit exceeded](http://stackoverflow.com/questions/1393486/error-java-lang-outofmemoryerror-gc-overhead-limit-exceeded) – Vivek Mishra Sep 07 '16 at 06:31

2 Answers2

0

Just add below lines to your build.gradle file.

dexOptions {
        javaMaxHeapSize "4g"
 }

I hope this will help you.

Mayank Pandya
  • 265
  • 3
  • 14
0

Selecting CMS garbage collection has a bad effect on JVM's dimensioning of the JVM "New Space". If that space is too small, then you'll constantly see (young generation) GC, which may lead to your problem.

E.g.,

/usr/bin/java -Xms4096m -Xmx4096m -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -version

reports just 160 MB of "New space", despite of a total 4 GB heap size. This was on a 2 core system (the number increases with the number of cores), using JVM 1.7.0_75.

You should check what's your result using a similar command -- look for the line par new generation total ...K. If the number appears very low, then this is the root cause of your problem.

You can then solve this by adding the options -XX:NewRatio=2 -XX:NewSize=512m, which will explicitly...

  • apply the standard dimensionsing rule for the upper limit on "New space" to one third of the available heap space
  • set the minimum "New space" size to 512m

In general, you should be very careful with tuning the GC settings, like, adding -XX:+UseConcMarkSweepGC -- without that option, the bad dimensioning wouldn't appear in the first place.

Alex O
  • 7,746
  • 2
  • 25
  • 38