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.
我已经使用Android Studio 3个月了,我开始使用它的一个应用程序已经变得相当大了。程序右下角显示的内存使用情况表明,分配的堆最大为494M。
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.
当我开始更改XML文件时,我的内存使用量很快就达到了这个上限,IDE崩溃时就会出现这样的内存溢出错误。
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.
我已经阅读了几十篇关于如何增加堆大小的文章和其他问题,但是他们的答案都没有起作用。无论我对VMOPTIONS或IDE设置做什么,堆大小都不会增加。我相信我正在为VMOPTIONS编辑正确的文件,因为如果我故意给它一个无效的命令,Android Studio会对它提出抱怨,而且不会启动。
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?
我使用的是windows 7 - 64位,内存16GB。有谁对Android Studio有过这样的问题吗?你能修好它吗?
104
Open file located at /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions
Change the content to
打开位于/Applications/Android\ Studio.app/ content /bin/studio的文件。vmoptions将内容更改为。
-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.
Xmx指定Java虚拟机(JVM)的最大内存分配池,而Xms指定初始内存分配池。您的JVM将使用Xms数量的内存启动,并且能够使用最大的Xmx数量的内存。
Save the studio.vmoptions
file and restart Android Studio.
保存工作室。vmoptions文件,重启Android Studio。
More at this post.
在这篇文章。
---------- EDIT ----------
- - - - - - - - - - -编辑- - - - - - - - - - -
Android Studio 2.0, you can create/edit this file by accessing "Edit Custom VM Options" from the Help menu.
Android Studio 2.0,您可以通过从帮助菜单中访问“编辑自定义VM选项”来创建/编辑这个文件。
47
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).
或者,您可以访问android-studio\bin文件夹,并在studio.exe中更改这些-Xmx和-Xms值。vmoptions或studio64.exe。vmoptions文件(取决于您正在运行的版本)。
42
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.
我查看了我的环境变量,并有一个名为_JAVA_OPTIONS的系统变量,其值为-Xms256m -Xmx512m,将其更改为-Xms256m -Xmx1024m后,最大堆大小随之增加。
20
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).
您不应该在IDE安装目录中编辑任何文件。相反,您可以通过在以下目录中创建自己的.properties或.vmoptions文件来定制属性。(这在以前的一些平台上是可能的,但是它要求您复制和更改文件的全部内容。对于最新的更改,这些属性现在是可添加的,这样您就可以只设置您关心的属性,其余属性将使用IDE安装的默认值)。
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.
注意:在Android Studio 2.0中,您可以通过访问帮助菜单中的“编辑自定义VM选项”文件来创建/编辑该文件。
http://tools.android.com/tech-docs/configuration
http://tools.android.com/tech-docs/configuration
19
I increased my memory following the next Google documentation:
在接下来的谷歌文档中,我增加了内存:
http://tools.android.com/tech-docs/configuration
http://tools.android.com/tech-docs/configuration
By default Android Studio is assigned a max of 750Mb, I changed to 2048Mb.
默认情况下,Android Studio的最大内存为750Mb,我将其修改为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,
首先,我创建了一个名为。androidstudiosettings的目录,
mkdir .AndroidStudioSettings
Then I created a file called studio.vmoptions , and I put in that file the following content:
然后我创建了一个名为studio的文件。vmoptions,我在那个文件里放了以下内容:
-Xms256m
-Xmx2048m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=128m
-XX:+UseCompressedOops
Then I added the STUDIO_VM_OPTIONS environment variables in my .profile file:
然后,我在.profile文件中添加了STUDIO_VM_OPTIONS环境变量:
export STUDIO_VM_OPTIOnS=/Users/youruser/.AndroidStudioSettings/studio.vmoptions
Then I reload my .profile:
然后重新加载。profile:
source ~/.profile
And finally I open Android Studio:
最后我打开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:
现在你可以看到使用状态栏,我有超过2000 MB的Android Studio可用:
You can customize your values according to your need in my case 2048Mb is enough.
您可以根据您的需要定制您的值,在我的情况下,2048Mb就足够了。
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.
更新:Android Studio 2.0让我们通过从帮助菜单中访问“编辑自定义VM选项”来修改这个文件,只需复制并粘贴您可能想要保存的变量,以便在您的方框中增加everversion。
8
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.
如果这些都不适合你的话,试试这款Mac电脑,看看它对你是否有帮助。vmoptions在AndroidStudio中。应用程序在您的应用程序文件夹。
So right click or ctrl click on your AndroidStudio.App and then select show package content the studio.vmoptions is in:
右键单击或按ctrl单击AndroidStudio。应用,然后选择显示包内容的工作室。vmoptions是在:
Contents/bin/studio.vmoptions
/ bin / studio.vmoptions内容
Replace or change it and you will get all the RAM you need.
替换或更改它,您将获得所需的所有RAM。
Regards.
的问候。
6
There are a lot of answers that are now outdated. The desired way of changing the heap size for Android Studio recently changed.
现在有很多答案已经过时了。最近,改变Android Studio堆大小的方法发生了变化。
Users should now create their own vmoptions file in one of the following directories;
用户现在应该在以下目录中创建自己的vmoptions文件;
Windows: %USERPROFILE%\.{FOLDER_NAME}\studio64.exe.vmoptions
Windows:% USERPROFILE % \ { FOLDER_NAME } \ studio64.exe.vmoptions
Mac: ~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions
麦克:~ /图书馆/ / { FOLDER_NAME } / studio.vmoptions偏好
Linux: ~/.{FOLDER_NAME}/studio.vmoptions and/or ~/.{FOLDER_NAME}/studio64.vmoptions
Linux:~ /。{ FOLDER_NAME } /工作室。vmoptions和/或~ / { FOLDER_NAME } / studio64.vmoptions
The contents of the newly created *.vmoptions
file should be:
新创建的*的内容。vmoptions文件应该是:
-Xms128m
-Xmx750m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=96m
-XX:+UseCompressedOops
To increase the RAM allotment change -XmX750m
to another value.
为了增加RAM分配更改-XmX750m到另一个值。
Full instructions can be found here: http://tools.android.com/tech-docs/configuration
完整的说明可以在这里找到:http://tools.android.com/tech-docs/configuration
6
If you are using MAC BOOK, this option is available inside Applications -> Right click Android Studio then choose Show Package contents -> bin.
如果您正在使用MAC BOOK,这个选项可以在应用程序中使用——>右键单击Android Studio,然后选择Show Package contents——> bin。
or
或
open -e /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions
开放- e /应用程序/ Android \ Studio.app /内容/ bin / studio.vmoptions
Then increase Xmx
value
然后增加Xmx价值
-Xms128m
-Xmx2048m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
Now your Android Studio will be super-fast.
现在你的Android工作室将会非常快。
4
I tried the _JAVA_OPTIONS thing but it wasn't working for me still.
我尝试了_JAVA_OPTIONS,但它仍然不适合我。
In the end, what worked for me was the following:
最后,对我起作用的是:
-Xms2048m
-Xmx2048m
-XX:MaxPermSize=1024m
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled
-XX:+HeapDumpOnOutOfMemoryError
-Dfile.encoding=utf-8
4
First check how much memory allocated for your android studio to check that follow this steps :
首先检查为android studio分配了多少内存,按照以下步骤进行检查:
File -> Settings->Appearance & Behavior->Appearance
文件->设置->外观和行为->外观
then check the show memory indicator option like below image red highlighted part
然后检查显示内存指示器选项,如下图红色突出显示部分
In my case my RAM is 12Gb so i have allocated memory for android studio 6gb .To edit that follow this steps
在我的情况下,我的RAM是12Gb,所以我为android studio 6gb分配了内存
Help->Edit custom VM options
帮助- >编辑自定义VM选项
-Xmx6g
In my case, i have set it 6gb because my pc ram is 12 GB. Its upto you how much memory you want to allocate to your android studio
在我的例子中,我将它设置为6gb,因为我的pc ram是12gb。你想要分配多少内存给你的android工作室
3
On Windows 7, the configuration files at [INSTALL-LOCATION]\bin
seem to be ignored. Per the following Google documentation, the file to be modified should be here: %USERPROFILE%\.AndroidStudio\studio[64].exe.vmoptions
在Windows 7上,[INSTALL-LOCATION]\bin的配置文件似乎被忽略了。根据下面的谷歌文档,要修改的文件应该在这里:%USERPROFILE%\.AndroidStudio\studio[64].exe.vmoptions
http://tools.android.com/tech-docs/configuration
http://tools.android.com/tech-docs/configuration
Odd that there is no such file upon a clean install of Android Studio 1.1 from the developer site. And they are in the old (ignored) location. Once I copy the file (studio.exe.vmoptions
in my case) over and modify it, the change is respected.
奇怪的是,在开发人员站点上安装了Android Studio 1.1之后,却没有这样的文件。它们在旧的(被忽略的)位置。一旦我复制文件(studio.exe)。在我的例子中是vmoptions)对它进行修改和修改之后,修改就会得到尊重。
However, the fun doesn't stop there. There's an upper value for -Xmx
which may be related to the amount of memory in your system. I just bumped my machine's memory from 4Gb to 16Gb, and assumed I could set -Xmx
to 2048m
, but I found that if I set it to anything larger than 1500m,
Android Studio would silently fail to launch with no indication at all as to why. I have more RAM on the way, so it will be interesting to see if I can increase the value at that point.
然而,乐趣并不仅限于此。有一个-Xmx的上限值,它可能与系统中的内存数量有关。我刚刚把我的机器内存从4Gb调到16Gb,并假设我可以将-Xmx调到2048m,但是我发现如果我把它调到任何大于1500m的内存,Android Studio会无声地失败,根本不知道为什么会这样。我在路上有更多的内存,所以看我能不能增加那个点的值是很有趣的。
I hope this additional information is helpful. While all of the above replies were undoubtedly true at one point (and may still be in some environments), I found that this was the only approach that increased the memory used by AS for me.
我希望这些额外的信息能有所帮助。虽然以上所有的回答在某一时刻无疑都是正确的(并且可能仍然在某些环境中),但我发现这是唯一增加AS用于我的内存的方法。
2
I found on on Windows 7/8 (64-bit), as of Android Studio 1.1.0:
我在Windows 7/8(64位)上发现,Android Studio 1.1.0版:
[INSTALL_DIR]\bin\studio64.exe.vmoptions
be used (if it exists), otherwise it would always fall back to %USERPROFILE%.\AndroidStudio\studio[64].exe.vmoptions
[INSTALL_DIR]\ bin \ studio64.exe。可以使用vmoptions(如果存在的话),否则总是会回到%USERPROFILE%.\AndroidStudio\studio[64].exe.vmoptions
If you want the settings managed from %USERPROFILE%.\AndroidStudio\studio[64].exe.vmoptions
, just delete the one in the installation directory.
如果您想要从%USERPROFILE%管理设置。\AndroidStudio\studio[64].exe。vmoptions,只删除安装目录中的一个。
2
Go in the Gradle Scripts -> local.properties and paste this
进入等级脚本->本地。属性和粘贴这个
`org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m`
, if you want to change it to 512. Hope it works !
如果你想把它改成512。希望它能够工作!
2
you are not supposed to modify the bin/studio.exe.vmoptions file, which will be verified during applying update patch.
你不应该修改bin/studio.exe。vmoptions文件,在应用更新补丁时进行验证。
Solutions are here http://tools.android.com/tech-docs/configuration
解决方案是http://tools.android.com/tech-docs/configuration
copy that file into following location, then change the -Xmx1280m to whatever you want.
将该文件复制到以下位置,然后将-Xmx1280m更改为您想要的任何文件。
%USERPROFILE%\.{FOLDER_NAME}\studio.exe.vmoptions
and/or %USERPROFILE%\.{FOLDER_NAME}\studio64.exe.vmoptions
% USERPROFILE % \ { FOLDER_NAME } \ studio.exe。vmoptions和/或% USERPROFILE % \ { FOLDER_NAME } \ studio64.exe.vmoptions
%USERPROFILE%\.{FOLDER_NAME}\idea.properties
% USERPROFILE % \ { FOLDER_NAME } \ idea.properties
~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions
~/Library/Preferences/{FOLDER_NAME}/idea.properties
~ /图书馆/偏好/ { FOLDER_NAME } /工作室。vmoptions ~ /图书馆/ / { FOLDER_NAME } / idea.properties偏好
~/.{FOLDER_NAME}/studio.vmoptions
and/or ~/.{FOLDER_NAME}/studio64.vmoptions
~ / { FOLDER_NAME } /工作室。vmoptions和/或~ / { FOLDER_NAME } / studio64.vmoptions
~/.{FOLDER_NAME}/idea.properties
~ / { FOLDER_NAME } / idea.properties
2
Had this Xms
and Xmx
memory low issue happen to me any time I was working with the XML. I also tried increasing this memory, only to find that it just took a little longer for it to happen again.
如果我在处理XML时遇到了Xms和Xmx内存不足的问题。我也尝试增加这种记忆,结果发现它只是花了更长的时间才再次发生。
After getting very frustrated and almost deciding to convert all my current projects back over to Eclipse, which I did not want to do, I figured out what was causing it and was able to repeat this failure and prevent it every time.
在感到非常沮丧并几乎决定将所有当前的项目转换回Eclipse(这是我不想做的)之后,我找到了导致它的原因,并能够每次重复此失败并防止它。
While editing the XML in (Text view), and using the "Preview" render view, this causes the loss of memory, every time. Turning off "Preview" and using the Design tab to render the screen only, I am able to use Android Studio all day long, with no crash.
在(文本视图)中编辑XML并使用“预览”呈现视图时,每次都会导致内存丢失。关闭“预览”并使用Design选项卡只显示屏幕,我可以整天使用Android Studio,不会崩溃。
I wish this could be fixed for good, because it would be very nice to use the "Preview" render while editing the XML, however I am glad I can keep using Android Studio.
我希望这个问题能得到永久的解决,因为在编辑XML时使用“预览”呈现会很好,但是我很高兴我可以继续使用Android Studio。
1
Open studio.vmoptions and change JVM options
开放的工作室。vmoptions并更改JVM选项
studio.vmoptions locates at /Applications/Android\ Studio.app/bin/studio.vmoptions (Mac OS). In my machine, it looks like
工作室。vmoptions位于/Applications/Android\ Studio.app/bin/studio。vmoptions(Mac OS)。在我的机器里,它看起来像
-Xms128m
-Xmx800m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
Change to
改变
-Xms256m
-Xmx1024m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
And restart Android Studio
并重新启动Android工作室
See more Android Studio website
查看更多的Android Studio网站
1
May help someone that get this problem:
可能会帮助遇到这个问题的人:
I edit studio64.exe.vmoptions
file, but failed to save.
我编辑studio64.exe。vmoptions文件,但是保存失败。
So I opened this file with Notepad++ in Run as Administrator
mode and then saved successfully.
因此,我以运行为管理员模式的Notepad++打开这个文件,然后成功保存。
1
-Xms256m
-Xmx2048m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=128m
-XX:+UseCompressedOops
1
IF by changing or creating the .studio.exe.vmoptions
doesn't work, then try changing the gradle.properties
file and change the heap size as per your requirement.
如果通过改变或创建。studio.exe。vmoptions不起作用,然后尝试更改等级。属性文件,并根据需要更改堆大小。
It really worked for me on my Windows 7 with 4Gb RAM and Android Studio 2.2 install on it.
在我的Windows 7上,它真的很好用,有4Gb的RAM和Android Studio 2.2。
Working properly with no error and displaying 'Gradle Sync complete'
正常工作,没有错误,显示'渐变同步完成'
0
Android Studio 3.1 has option to edit your customize virtual memory options.
Android Studio 3.1有编辑自定义虚拟内存选项的选项。
You can go Android Studio > Help > Edit Custom VM Options
你可以去Android Studio >帮助>编辑自定义VM选项
Then paste below settings code to studio64.ex.vmoptions file & Save it.
然后将下面的设置代码粘贴到studio64.ex中。vmoptions文件并保存。
-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops.