[FIXED] Expiring Daemon because JVM heap space is exhausted

Issue

I just updated the Android Studio to 3.5 Beta 1 and I’m getting

Expiring Daemon because JVM heap space is exhausted

message while the build is running. Also, the build is taking more time to complete. Does anyone have any idea regarding this?

Solution

This can be fixed by increasing the configured max heap size for the project.

Through IDE:

Add the below lines into the gradle.properties file. Below memory size (1) can be configured based on the RAM availability

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2560m

Through GUI:

In the Settings, search for ‘Memory Settings’ and increase the IDE max heap size and Daemon max heap size as per the system RAM availability.

Memory Settings in Android Studio

(1)

$ man java
...
-Xmxsize
    Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value
    must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate
    kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value
    is chosen at runtime based on system configuration. For server deployments, -Xms and
    -Xmx are often set to the same value. See the section "Ergonomics" in Java SE HotSpot
    Virtual Machine Garbage Collection Tuning Guide at
    http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.

    The following examples show how to set the maximum allowed size of allocated memory to
    80 MB using various units:

        -Xmx83886080
        -Xmx81920k
        -Xmx80m

    The -Xmx option is equivalent to -XX:MaxHeapSize.
...

Answered By – Rishabh Sagar

Answer Checked By – Dawn Plyler (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published