By default, Android Studio has a maximum heap size of 1280MB. If you are working on a large project, or your system has a lot of RAM, you can improve performance by increasing the maximum heap size for Android Studio processes, such as the core IDE, Gradle daemon, and Kotlin daemon.
You can increase to 2GB on a 32 bit system. If you're on a 64 bit system you can go higher.
Use -Xmx to specify the maximum heap size. Use -Xms to specify the initial Java heap size. Use -Xss to set the Java thread stack size.
Most devices running Android 2.3 or later will return this size as 24MB or higher but is limited to 36 MB (depending on the specific device configuration). If your app hits this heap limit and tries to allocate more memory, it will receive an OutOfMemoryError and will terminate. Heap memory is used to allocate objects.
Android Studio 2.0 and above, you can create/edit this file by accessing "Edit Custom VM Options" from the Help menu.
Open file located at
/Applications/Android\ Studio.app/Contents/bin/studio.vmoptions
Change the content to
-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
Xmx
specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms
specifies the initial memory allocation pool. Your JVM will be started with Xms
amount of memory and will be able to use a maximum of Xmx
amount of memory.
Save the studio.vmoptions
file and restart Android Studio.
If you changed the heap size for the IDE, you must restart Android Studio before the new memory settings are applied. (source)
I looked at my Environment Variables and had a System Variable called _JAVA_OPTIONS
with the value -Xms256m -Xmx512m
, after changing this to -Xms256m -Xmx1024m
the max heap size increased accordingly.
Or, you can go to your android-studio\bin
folder and change these -Xmx and -Xms values in studio.exe.vmoptions
or studio64.exe.vmoptions
files (depending on which version you are running).
You should not edit any files in the IDE installation directory. Instead, you can customize the attributes by creating your own .properties or .vmoptions files in the following directories. (This has been possible on some platforms before, but it required you to copy and change the entire contents of the files. With the latest changes these properties are now additive instead such that you can set just the attributes you care about, and the rest will use the defaults from the IDE installation).
Note: As of Android Studio 2.0, you can create/edit this file by accessing the "Edit Custom VM Options" file from the Help menu.
http://tools.android.com/tech-docs/configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With