Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High memory usage by gradle daemon

People also ask

How much memory does gradle use?

How much memory does the Daemon use and can I give it more? If the requested build environment does not specify a maximum heap size, the Daemon will use up to 512MB of heap. It will use the JVM's default minimum heap size. 512MB is more than enough for most builds.

How do I stop gradle Daemon?

If you wish to stop a Daemon process manually, you can either kill the process via your operating system task manager or run the gradle --stop command. The --stop switch causes Gradle to request that all running Daemon processes, of the same Gradle version used to run the command, terminate themselves.

What is gradle Daemon in Android Studio?

The solution to this problem is Gradle Daemon. The Gradle daemon is a background process that can execute builds very quickly. Using this, we can avoid expensive bootstrapping process and cache, by keeping the data about the project into the memory. We can run Gradle builds with Daemon.

How much RAM should I allocate to gradle?

You should stay at the sensible level of 2–4 gigabytes for gradle and 1–2 for dex.


Following Antoniossss' advice I got in touch with a developer. As it turns out, Gradle is in fact quite resource hungry. Even for a simple "Hello World" application the daemon might use very well up to 150 MB and maybe even more. It is also alright, that multiple daemon threads are started, as long as they run within the same JVM. There is only limited control on the user's side to control/limit memory usage. One could set GRADLE_OPTS variable in order to pass Xmx options to the JVM, e.g., I managed to build my Android project with following settings:

$ export GRADLE_OPTS="-Xmx64m -Dorg.gradle.jvmargs='-Xmx256m -XX:MaxPermSize=64m'"

The first -Xmx option is set for the Gradle that you start in CLI, the second one (after -Dorg.gradle.jvmargs) is the -Xmx value for the Gradle-Daemon.

The less memory you allow for your JVM the higher the risk for your build to fail - obviously. So you might have to tune those settings until they suit your purposes.

Those settings can also be set in the gradle.properties file.