Android Studio - How to increase Allocated Heap Si

2019-01-01 15:04发布

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?

20条回答
忆尘夕之涩
2楼-- · 2019-01-01 15:22

I increased my memory following the next Google documentation:

http://tools.android.com/tech-docs/configuration

By default Android Studio is assigned a max of 750Mb, I changed to 2048Mb.

I tried what google described but for me the only thing that it worked was to use an environment variable. I will describe what I did:

First I created a directory that I called .AndroidStudioSettings,

  • mkdir .AndroidStudioSettings

Then I created a file called studio.vmoptions , and I put in that file the following content:

-Xms256m 
-Xmx2048m 
-XX:MaxPermSize=512m 
-XX:ReservedCodeCacheSize=128m 
-XX:+UseCompressedOops 

Then I added the STUDIO_VM_OPTIONS environment variables in my .profile file:

  • export STUDIO_VM_OPTIONS=/Users/youruser/.AndroidStudioSettings/studio.vmoptions

Then I reload my .profile:

  • source ~/.profile

And finally I open Android Studio:

  • open /Applications/Android\ Studio.app

And now as you can see using the status bar , I have more than 2000 MB available for Android Studio:

enter image description here

You can customize your values according to your need in my case 2048Mb is enough.

UPDATE : Android Studio 2.0 let's you modify this file by accessing "Edit Custom VM Options" from the Help menu, just copy and paste the variables you might want to keep in order to increase it for everversion you might have on your box.

查看更多
人间绝色
3楼-- · 2019-01-01 15:23

Android Studio 3.1 has option to edit your customize virtual memory options.

You can go Android Studio > Help > Edit Custom VM Options

enter image description here

Then paste below settings code to studio64.ex.vmoptions file & Save it.

-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops.
查看更多
姐姐魅力值爆表
4楼-- · 2019-01-01 15:24

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

enter image description here

查看更多
千与千寻千般痛.
5楼-- · 2019-01-01 15:25

May help someone that get this problem:

I edit studio64.exe.vmoptions file, but failed to save.

So I opened this file with Notepad++ in Run as Administrator mode and then saved successfully.

查看更多
妖精总统
6楼-- · 2019-01-01 15:27

you are not supposed to modify the bin/studio.exe.vmoptions file, which will be verified during applying update patch.

Solutions are here http://tools.android.com/tech-docs/configuration

copy that file into following location, then change the -Xmx1280m to whatever you want.

Windows:

%USERPROFILE%\.{FOLDER_NAME}\studio.exe.vmoptions and/or %USERPROFILE%\.{FOLDER_NAME}\studio64.exe.vmoptions

%USERPROFILE%\.{FOLDER_NAME}\idea.properties

Mac:

~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions ~/Library/Preferences/{FOLDER_NAME}/idea.properties

Linux:

~/.{FOLDER_NAME}/studio.vmoptions and/or ~/.{FOLDER_NAME}/studio64.vmoptions

~/.{FOLDER_NAME}/idea.properties

查看更多
妖精总统
7楼-- · 2019-01-01 15:29

Note: I now this is not the answer for the post, but maybe this will be helpful for some one that is looking.

If Nothing of this works for you, try on a Mac this to see if helps you, in the last version of Android Studio, the studio.vmoptions is inside the AndroidStudio.app in your Applications folder.

So right click or ctrl click on your AndroidStudio.App and then select show package content the studio.vmoptions is in:

Contents/bin/studio.vmoptions

Replace or change it and you will get all the RAM you need.

enter image description here enter image description here

Regards.

查看更多
登录 后发表回答