Android Studio - How to increase Allocated Heap Size

zafrani picture zafrani · Sep 10, 2013 · Viewed 198.1k times · Source

I've been using Android Studio for 3 months now and one of the apps I started on it has become fairly large. The memory usage indicated at the bottom right of the program says my allocated heap is maxed at 494M.

enter image description here

When I start to change the XML files my memory usage quickly reaches that cap and the IDE crashes with an Out Of Memory error like this.

enter image description here

I've tried to increase the heap size using this but so far there has been no effect.

I've looked at dozens of articles and other questions on how to increase the heap size but none of their answers are working. No matter what I do to the VMOPTIONS or the IDE settings the heap size never increases. I believe I am editting the correct file for the VMOPTIONS because if I purposely give it an invalid command Android Studio complains about it and doesn't start.

I'm using windows 7 - 64 bit and have 16GB RAM. Has anyone else had this problem with Android Studio? And were you able to fix it?

Answer

Wesley picture Wesley · Feb 26, 2015

-------EDIT--------

Android Studio 2.0 and above, you can create/edit this file by accessing "Edit Custom VM Options" from the Help menu.

-------ORIGINAL ANSWER--------

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.

More at this post.

Note:

If you changed the heap size for the IDE, you must restart Android Studio before the new memory settings are applied. (source)