208

I had installed Android Studio 1.0 RC 2. I have 4GB of RAM installed, but after starting Android Studio and launching Android Emulator, more than 90% of physical memory has been used by only these two. Is there is any way to reduce this memory use? Due to this memory issue, I can't open other applications at the same time. enter image description here

Zoe
  • 27,060
  • 21
  • 118
  • 148
PPD
  • 5,660
  • 12
  • 52
  • 86
  • 20
    Using Eclipse or Android Studio, and an emulator, on a 4GB Windows development machine will be very painful. I would **strongly** recommend that you either upgrade your development machine's RAM (8GB or more), test on a device (instead of an emulator), or skip the IDE and do your development using a plain editor and command-line tools. – CommonsWare Nov 27 '14 at 17:42
  • 2
    I guess you're using Windows judging by the screenshot you've posted. But which version of Windows? Also, since Android Studio is still in its infancy, you'll get many issues with it. If you don't need Gradle support, you can always try Eclipse - the IDE has been tried-and-tested over the years so it's quite solid for a development environment - RAM wise. – ChuongPham Nov 27 '14 at 17:48
  • 1
    @CommonsWare Do you know if the same is true for Linux PC? Thanks in advance. – Alexander Kulyakhtin Nov 27 '14 at 17:50
  • I am using windows7 OS – PPD Nov 27 '14 at 17:52
  • 1
    @Alex: There seems to be a bit less overhead on Linux. That being said, 4GB on Linux would be snug. I use Ubuntu for my main environment, and on 8GB, Android Studio, an emulator, and other tools (browser, PDF viewer, terminal, etc.) all fit comfortably (right now, using about 4GB of my 8GB). – CommonsWare Nov 27 '14 at 17:52
  • 4
    @PPD: In Windows, turn off unnecessary services via **Administrative Tools | Services** option. Go to `msconfig` and turn off unnecessary applications in **Startup** tab. Turn off unnecessary Visual Effects in Windows. When you run an Android emulator, turn on **Use Host GPU** option particularly if you have a powerful graphic card. I have a Windows 7 development PC and I only use 2-2.5GB of RAM at any one time that includes having: Windows 7, Eclipse, Mozilla Firefox (no add-ons) and the Windows customisation steps I just mentioned. I also use Fedora and it uses even less memory than Windows. – ChuongPham Nov 27 '14 at 18:03
  • Visit my answer on [this thread][1] [1]: http://stackoverflow.com/a/28876389/1923688 – Vahid Haratian Mar 05 '15 at 11:10
  • 3
    Just an observation: I can see you have some Google Chrome tabs open. You *might* find that Firefox uses a bit less RAM since it doesn't use a process per browser tab. – Sam May 26 '15 at 03:16
  • I'm currently using Andriod Studio 1.2.2 on 32bit Ubuntu 14.04 with 4gb Ram. I can't even load the inbuilt emulator with my specs. I use Genymotion which is little more efficient but even that is a drag at times. I would certainly love the idea of using plain-text editor but for that I need to have some degree of mastery over the environment. Definitely maybe later... – thethakuri Aug 01 '15 at 04:54
  • filed a bug.. https://code.google.com/p/android/issues/detail?id=183953&thanks=183953&ts=1440603319 would love to have the git working but not with that load... please star the bug, then it gets fixed hopefully – Martin Mlostek Aug 26 '15 at 15:36
  • I had the same problem, and recently I added 4GB RAM, which improved the performance very much. I recommend the same to you. – Vishnu Haridas Feb 17 '16 at 08:42
  • Developers who are testing/developing this POS IDE for Android in Google HQ are running these specs: Intel XEON E7 2ghz 64gb of RAM 4TB of ULTRA FAST SSD! Also most Android devs in Google HQ are developing native apps for Nexus on their Mainframe computers. I believe this is their minimum spec for Android Studio – Neon Warge May 09 '16 at 10:40
  • I had to disable windows update service. I had problems running android studio. Android studio + emulator certainly takes lot of memory but I my emulator was taken ages even to launch. Later on it turned out that one of the svchost.exe processes hosting windows updates service was taking too much memory. I was on a windows 7 box with 4 GB RAM 6th gen i3 intel processor. You can check this thread [here](http://superuser.com/questions/583737/why-how-is-svchost-exe-using-6-5gb-of-memory) and [here](http://superuser.com/questions/821032/svchost-exe-high-memory-usage-wuauserv) – RBT Nov 14 '16 at 04:52

13 Answers13

249

I'm currently running Android Studio on Windows 8.1 machine with 6 gigs of RAM.

I found that disabling VCS in android studio and using an external program to handle VCS helped a lot. You can disable VCS by going to File->Settings->Plugins and disable the following:

  • CVS Integration
  • Git Integration
  • GitHub
  • Google Cloud Testing
  • Google Cloud Tools Core
  • Google Cloud Tools for Android Studio
  • hg4idea
  • Subversion Integration
  • Mercurial Integration
  • TestNG-J
jds17
  • 2,531
  • 1
  • 10
  • 12
  • 21
    nah, very small change. – krivar Jun 14 '15 at 10:01
  • I tried disabling all the VCS plugins I *wasn't* using, and I didn't notice any difference. – Sam Jun 17 '15 at 09:12
  • 1
    Helped a lot. Even 2 gb of memory allowance wasn't any help in Studio. Cheers – wtk Aug 25 '15 at 09:15
  • @Sam any form of VCS on android studio causes it to aggressively compare differences between the code you're writing and the existing code in your repo. It's either an all or nothing disable. – jds17 Aug 25 '15 at 17:57
  • please star the android studio bug. https://code.google.com/p/android/issues/detail?id=183953&thanks=183953&ts=1440603319 – Martin Mlostek Aug 26 '15 at 15:36
  • After disabling listed plugins considerable difference of speed noticed in windows 7. – Deshan Aug 29 '15 at 16:04
  • 8
    Huge difference when your project is configured with any repository like svn or github. my execution wait time reduced from >3min to <1min. Thanks a lot for amazing help. – Er. Kaushik Kajavadara Jul 20 '16 at 07:26
  • 4
    This seems to work and makes a big difference, although I kept 'Git Integration' switched on. Ideally Android Studio should have these as the default settings. – Mr-IDE Aug 14 '16 at 09:27
  • 3
    I used this method for HP 6005 mini case with 4GB ram and amd X4 Cpu . after deactived all of these plugins my android studio opened very very fast i cant believe . before starting the android studio take a 15 second but now it come up in 1 second . thanks – SAYE Dec 18 '16 at 15:52
  • 1
    Thanks Mate , It really helped a lot!! I have a hexa-core cpu with 4gb ram on ssd – BeatingBytes Aug 02 '17 at 00:01
  • Most of these seemed to be turned off by default in Studio v3.0.1, except for the systems I have installed (Git & Subversion). I disabled the unused one (SVN), and that helped a fair bit. – MandisaW Mar 26 '18 at 19:19
  • 3
    Also disable Mercurial Integration, TestNG-J; – xiaoweiz Apr 03 '19 at 03:17
  • why this plugin consume so much ram? – Rafael Guimarães Sep 11 '19 at 19:08
  • After doing this, My 8 RAM's usage dropped from 82% to 62%..! (AS 3.6, Windows 10, 8GB). Thanks a lot. – Dharmesh G Mar 12 '20 at 17:02
  • Yes, I can also confirm that the RAM usage of AS dropped from 2.2GB to 1.5GB. Amazing, thanks! – Vladimir Marton Aug 07 '21 at 15:03
118

In my case, there were two main sources of memory hogging: the IDE and Gradle:

Android Studio (up to 1.5GB)

The IDE's JVM is configured to have a max heap size. You can see this in the lower-right corner of the main interface:

Android Studio showing 725M max heap size

You can reduce this by editing the memory-related settings in the .vmoptions file. For example, I changed my max heap size to 512MB:

-Xmx512m

Unfortunately, I found that lowering this value increases the frequency of Android Studio temporarily freezing, perhaps to do its garbage collection.

Gradle (up to 1.5GB)

Gradle can also use a lot of RAM after developing for a while. Windows just shows it as Java(TM) Platform SE Binary:

Windows 8.1 Task Manager showing "Java(TM Platform SE binary" using 1,460.5 MB of memory

You can fix this by changing the Gradle JVM options. You can do this on a per-user basis by editing gradle.properties:

  1. Open the gradle.properties file, creating it if it doesn't exist:
    • Windows: %USERPROFILE%\.gradle\gradle.properties
    • Linux/Mac: ~/.gradle/gradle.properties
  2. Update the org.gradle.jvmargs property, creating it if necessary. I set mine to this:

    org.gradle.jvmargs=-Xmx256m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    

I haven't noticed any difference in build performance for my small project with the max heap size set to 256MB (-Xmx256m).

Note that you might need to restart Android Studio so the old Gradle process is killed; otherwise you might end up with both running at the same time.

Emulator

Regarding the emulator taking up a lot of your RAM, your screenshot shows it taking about 800MB. You can choose how much RAM to allocate to the emulator:

  1. Edit the AVD
  2. Press Show Advanced Settings
  3. Reduce the value of RAM

Android Virtual Device RAM configuration

Sam
  • 40,644
  • 36
  • 176
  • 219
  • This in conjunction with SoJexy's answer dramatically increased the performance on my computer. – Josh Larson May 28 '15 at 15:53
  • These tips were a life-saver! There is also an option to change the heap size used by the dex compiler which further reduces memory use. Details: http://techzog.com/development/android-studio-high-ram-usage/ – Varun Jun 19 '15 at 08:32
  • 1
    In the `.vmoptions` file it says: `*DO NOT* modify this file directly. If there is a value that you would like t$ please add it to your user specific configuration file. See http://tools.android.com/tech-docs/configuration` However, since there doesn't seem to be a user specific file on my system and the website doesn't explain any other locations of such a file, I'll go with this solution. Oh and: MaxPermSize will be deprecated at some point. It always warns me about that when starting IDEs in terminal. – Zelphir Kaltstahl Nov 18 '15 at 12:07
  • 1
    @Zelphir, which OS and Android Studio version are you using? I'm using Windows and the instructions say the file is under `%USERPROFILE%`, which is user-specific. I'm not very good at Linux, but the Mac and Linux instructions also say the file is under `~`, which I guess is the user's home directory? If the file isn't present, maybe you can just create it; the documentation referred to above says `Instead, you can customize the attributes by creating your own .properties or .vmoptions files in the following directories.`. Could you let me know if it works so I can update the answer? – Sam Nov 18 '15 at 21:12
  • There is no such file in my `~` directory, but I disabled some version control integration, which I always do from terminal and that helped already and I didn't create a new configuration file. Maybe there was no file because I didn't use package manager to install it, but simply downloaded and extracted Android Studio and in this case it might not create the file. – Zelphir Kaltstahl Nov 18 '15 at 23:49
  • 3
    Awesome suggestions! For Gradle, I solved the issue in a "user-wide" manner by editing `~/.gradle/gradle.properties`. – Andrea Lazzarotto Mar 29 '16 at 19:16
  • @AndreaLazzarotto, I just tested out your suggestion and it seems to be working fine. Thanks! – Sam Apr 27 '16 at 22:22
  • @Sam, I am glad it worked. Thank *you* for the great tips in the answer. :) – Andrea Lazzarotto Apr 27 '16 at 23:45
  • Thanks for the reminder about Gradle's RAM requirement. I had originally lowered it from 10GB to 2GB. But as of Studio v3.0.1, even testing without the emulator was pushing that limit. Bumped jvmargs up to 4GB (out of hardware 8GB), and she's running smooth as silk now :) – MandisaW Mar 26 '18 at 19:22
  • is 512m ram enough for latest ASv3? – Khemraj Sharma Apr 25 '18 at 11:00
54

You can speed up your Eclipse or Android Studio work, you just follow these:

  • Use/open single project at a time
  • clean your project after running your app in emulator every time
  • use mobile/external device instead of emulator
  • don't close emulator after using once, use same emulator for running app each time
  • Disable VCS by using File->Settings->Plugins and disable the following things :
    1.CVS Integration
    2.Git Integration
    3.GitHub
    4.Google Cloud Tools for Android Studio
    5.Subversion Integration

I am also using Android Studio with 4-GB installed main memory but following these statements really boost my Android Studio performance.

KulArtist
  • 965
  • 8
  • 20
32

Android Studio has recently published an official guide for low-memory machines: Guide

If you are running Android Studio on a machine with less than the recommended specifications (see System Requirements), you can customize the IDE to improve performance on your machine, as follows:

  • Reduce the maximum heap size available to Android Studio: Reduce the maximum heap size for Android Studio to 512Mb.

  • Update Gradle and the Android plugin for Gradle: Update to the latest versions of Gradle and the Android plugin for Gradle to ensure you are taking advantage of the latest improvements for performance.

  • Enable Power Save Mode: Enabling Power Save Mode turns off a number of memory- and battery-intensive background operations, including error highlighting and on-the-fly inspections, autopopup code completion, and automatic incremental background compilation. To turn on Power Save Mode, click File > Power Save Mode.

  • Disable unnecessary lint checks: To change which lint checks Android Studio runs on your code, proceed as follows: Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.In the left pane, expand the Editor section and click Inspections. Click the checkboxes to select or deselect lint checks as appropriate for your project. Click Apply or OK to save your changes.

  • Debug on a physical device: Debugging on an emulator uses more memory than debugging on a physical device, so you can improve overall performance for Android Studio by debugging on a physical device.

  • Include only necessary Google Play Services as dependencies: Including Google Play Services as dependencies in your project increases the amount of memory necessary. Only include necessary dependencies to improve memory usage and performance. For more information, see Add Google Play Services to Your Project.

  • Reduce the maximum heap size available for DEX file compilation: Set the javaMaxHeapSize for DEX file compilation to 200m. For more information, see Improve build times by configuring DEX resources.

  • Do not enable parallel compilation: Android Studio can compile independent modules in parallel, but if you have a low-memory system you should not turn on this feature. To check this setting, proceed as follows: Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog. In the left pane, expand Build, Execution, Deployment and then click Compiler. Ensure that the Compile independent modules in parallel option is unchecked.If you have made a change, click Apply or OK for your change to take effect.

  • Turn on Offline Mode for Gradle: If you have limited bandwitch, turn on Offline Mode to prevent Gradle from attempting to download missing dependencies during your build. When Offline Mode is on, Gradle will issue a build failure if you are missing any dependencies, instead of attempting to download them. To turn on Offline Mode, proceed as follows:

    • Click File > Settings (on a Mac, Android Studio > Preferences) to open the Settings dialog.

    • In the left pane, expand Build, Execution, Deployment and then click Gradle.

    • Under Global Gradle settings, check the Offline work checkbox.

    • Click Apply or OK for your changes to take effect.

Ivan Fateev
  • 1,032
  • 1
  • 10
  • 26
Androidmeda
  • 321
  • 3
  • 2
17

I have used all of Sam's recommendations above, but I found that the VM command line options are no longer supported as described. (I received an error when used)

As an alternative, I was able to reduce gradle dramatically by adding the following line to the "gradle.properties" file

org.gradle.jvmargs=-Xms512m -Xmx1024m

As of A.S. ver 1.3, the file is located in the same folder level as "gradle.build".

The above configuration is a "memory stack" of 512 meg, and "memory heap" of 1024 meg.

I tested this on a small project, using settings where both memory sizes were set to 256 meg. It limited the JVM sizes as expected. In all my tests, I restarted A.S. to force the JVM to restart.

Hopefully, this will save others dealing with this issue from getting those "Get yourself a better computer" responses. :-)

Dilber

SpacemanScott
  • 953
  • 9
  • 21
  • Thanks; this worked for me in AS 1.3! I updated the instructions in my answer to cover this method since I haven't found any other ways to do it in AS 1.3. – Sam Aug 26 '15 at 09:27
4

You can adjust the heap size of the IDE and Gradle daemons from inside the Android Studio.

Read and follow the instructions in the IDE settings screen:

Android Studio memory settings

Also, see this page on Android Developers site

Mahozad
  • 18,032
  • 13
  • 118
  • 133
3

To run Android envirorment on low configuration machine.

  1. Close the uncessesory web tabs in browser
  2. For Antivirus users, exclude the build folder which is auto generated
  3. Android studio have 1.2 Gb default heap can decrease to 512 MB

Help > Edit custom VM options

studio.vmoptions
 -Xmx512m

Layouts performace will be speed up

  1. For Gradle one of the core component in Android studio Mkae sure like right now 3.0beta is latest one

Below tips can affect the code quality so please use with cautions:

  1. Studio contain Power safe Mode when turned on it will close background operations that lint , code complelitions and so on.

  2. You can run manually lint check when needed ./gradlew lint

  3. Most of are using Android emulators on average it consume 2 GB RAM so if possible use actual Android device these will reduce your resource load on your computer. Alternatively you can reduce the RAM of the emulator and it will automatically reduce the virtual memory consumption on your computer. you can find this in virtual device configuration and advance setting.

  4. Gradle offline mode is a feature for bandwidth limited users to disable the downloading of build dependencies. It will reduce the background operation that will help to increase the performance of Android studio.

  5. Android studio offers an optimization to compile multiple modules in parallel. On low RAM machines this feature will likely have a negative impact on the performance. You can disable it in the compiler settings dialog.

Smit Patel
  • 1,174
  • 3
  • 26
  • 40
  • "studio.vmoptions -Xmx512m" killed Android studio for me. Will no longer open "Failed to create JVM: error code -1". How can I reverse this change? – MeatPopsicle Mar 28 '19 at 09:08
  • 1
    In case anyone else falls into the same trap. You can fix it by going to C:\Users\\.AndroidStudio\config and looking for a .vmoptions file. If it matches the config you just added you're probably safe to delete it – MeatPopsicle Mar 28 '19 at 10:53
2

I have Android Studio 2.1.1 Bro use genymotion emulator It Faster If Use Android Marshmallow. And My Ram Is 4gb.And Install Plugin for genymotion in Android Studio.You Will see good result in instead of wasting time start android emualtor it will take 5 min.genymotion 10 to 20 second speed and faster so I recommended to you use genymotion.

Nick
  • 39
  • 5
2

To reduce the lag i would recommend the follwing steps

my pc specs : 2 gb ram, processor: intel core2 duo

first kill all background process, if you have server or database running you could stop them first with following commands

sudo service apache2 stop

sudo service mysql stop

Then enable power saving mode in android studio by file>powersaving mode

It could disable background process, and then studio appears to go well

Naveen
  • 769
  • 1
  • 9
  • 28
2

Try switching your JVM to eclipse openj9. Its gonna use way less memory. I swapped it and its using 600Mb constantly.

2

I don't know if it is a solution but Invalidate Cache and Restart solved this problem in my case. I am currently using Android Studio 3.6

Aziz
  • 1,976
  • 20
  • 23
1

I fond this YouTube video from Google where are some tips and tricks for it. The video also includes advantages and disadvantages of suggested changes.

Improving Android Studio Performance on Memory-Constrained Machines

maresmar
  • 1,449
  • 14
  • 21
1

Open below mention path on your system and delete all your avd's (Virtual devices: Emulator)

C:\Users{Username}.android\avd

Note: - Deleting Emulator only from android studio will not delete all the spaces grab by their avd's. So delete all avd's from above given path and then create new emulator, if you needed.

Narender Gusain
  • 2,220
  • 17
  • 13
  • 1
    I deleted almost 9GB from the path you mentioned, these avds were deleted from android studio long before, thank you so much! – Meenohara Dec 14 '20 at 04:30