Android studio takes too much memory - performance

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.

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

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:
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:
You can fix this by changing the Gradle JVM options. You can do this on a per-user basis by editing gradle.properties:
Open the gradle.properties file, creating it if it doesn't exist:
Windows: %USERPROFILE%\.gradle\gradle.properties
Linux/Mac: ~/.gradle/gradle.properties
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:
Edit the AVD
Press Show Advanced Settings
Reduce the value of RAM

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.

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.

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. :-)

To run Android envirorment on low configuration machine.
Close the uncessesory web tabs in browser
For Antivirus users, exclude the build folder which is auto generated
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
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:
Studio contain Power safe Mode when turned on it will close background operations that lint , code complelitions and so on.
You can run manually lint check when needed ./gradlew lint
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.
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.
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.

You can adjust the heap size of the IDE and Gradle daemons from inside the Android Studio.
Read and follow the instructions in the settings screen:
Also, see this page on Android Developers site

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.

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

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

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

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

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.

Related

PC Lags after some Android Studio Flutter

Here are my PC Specs
Acer Aspire 5
Intel Core i3-8145U 2.1GHz with Turbo Boost up to 3.9GHz
RAM: 4GB DDR4
SSD: Kingston SUV500M8120G
OS: Windows 10
So I watched flutter tutorials...
I tried to do it with Android Studio... I installed it in hdd...
So I didn't care too much about the ram usage and the lag...
Two or three days ago, when the emulator was running, the machine suddenly froze...
After waiting for half an hour, I tried to get the task manager but it didn't, so I turned it off with the power button...
After that, I googled and said that it is difficult to run an emulator with my pc specs...
So I used my phone that day and connected it with a data cable...
Anyway, since the day of that freeze, the lap is slower than before...
The file explorer and also After pressing the windows key, it takes a while to open...
What is the reason for this???
I use Eset Internet Security...
I did a full scan of it and nothing...
I also tried the chkdsk command on all three partitions and there is no problem...
When I used Angular before, I used Webstrom...
It's not that bad as android studio, it wasn't slow...
Should I reset the pc???
There is no big case because only the software are uninstalled.....​​
Or should I install the android studio on the ssd...​
The problem I have is that even after closing the android studio, it lags...
Even after restarting the PC, it is the same
Tell me some solution guys, it's a big help...
It is necessary to have good about of ram, 16 GB is good, less 8 GB might feel laggy.
Android studio consume more than Visual Studio Code. I will suggest you to switch on VS Code, and upgrading your component, increase the ram. Resetting Pc won't help that much. Try to kill every background process, just use vs-code. If you like to build for android use real device.
As for learning, you can try on dart.dev

Android Emulator UI too large on Windows 10 20H2

I am using Android Studio 4.1.1 on Windows 10 20H2 with Hyper-V enabled on a computer with high DPI. Recently whenever I launch an AVD, the UI of the emulated device window becomes extremely large and impossible to use (as in the following screenshot). Other windows (including the AVD manager and the Android Studio itself) remains normal.
I have not used the emulator for a while, but I can make sure that the UI issue did not exist before I update my Windows to 20H2. I have also found similar questions on Stack Overflow (including this question), but the existing answers suggesting overriding its high DPI behavior does not work for me, because when I apply this setting, the emulator screen becomes so blurry that I cannot even recognize the texts on the screen.
How can I solve (or work around) this issue? Any help will be appreciated.
You can fix the scaling issue when using the Hardware rendering by simply making windows override the scaling setting. How?, it's very easy. Simply locate the .exe file for the emulator that you are using, (e.g. "qemu-system-armel.exe" for ARM and "qemu-system-x86_64.exe" for x86). To make sure which .exe file, just run the emulator then use task manager to locate the .exe file is running, see the screenshot. locate the .exe file using task manager
In my case it was in this location:
C:\Users[Username]\AppData\Local\Android\Sdk\emulator\qemu\windows-x86_64\qemu-system-x86_64.exe

Couldn't find disk developer image, Xcode Compatibility issue

I ran into this problem when iOS 10 was released. They are updating their device definitions so fast, that our small dev team can't match their speed. In result we need to develop on previous versions. But now our app crashes on 10.1 and we cannot debug. We need to wait for whole download to happen. Is it so hard to manage dev disk image to a place ? do they maintain disk image? or any other solution to the problem.

slow mozilla firefox build

I'm having a problem trying to build mozilla firefox. Despite the fact that my system is quite decent (i5 processor, 16 gb ram, ssd) , the build is very slow. I've used mk_add_options MOZ_MAKE_FLAGS="-j4" option in the mozconfig but my CPU is still at 1-2% of usage.
Is there something that I am missing?
The initial build can take from 10 minutes to more than an hour, depending on the OS, the build machine specs, and the build configuration.
Has your build finished at all? What do you call "slow"?
What OS are you building on? Windows, for example, is much slower to build.
What version of Firefox are you building (m-c tip? an old version?)
What's your build configuration (mozconfig)? Are you doing a debug or a release build? Any non-standard options? Did you try artifact builds?
Paste the build log, in particular it prints how much resources it took to build just before the end of the build.
Do you have A/V or other system software? Did you instruct it to ignore the objdir?

Xcode Instruments is stripping symbols despite all build settings to the contrary

Problem
Instruments' Time Profiler is stripping all symbols except system libraries from my app, despite the fact that I have disabled this behavior in all relevant build settings in Xcode — but only on one development machine. The other dev machine behaves normally.
Description
Instruments' Time Profiler is stripping all symbols except system libraries, despite the fact that I have disabled this behavior in all relevant build settings in Xcode — but this is only happening on one of my development machines. I have two development machines running the same version of OS X, Xcode, and Instruments, and each machine is using an identical copy of the same Xcode project with identical build settings, schemes, and other configurations, and the app is profiled using the same test device (iPhone 4S with the latest public version of iOS 5).
Machine 1
- Mac OS X 10.7.4
- Xcode 4.3.2 (4E2002)
- Instruments 4.3 (4321)
Machine 2
- Mac OS X 10.7.4
- Xcode 4.3.2 (4E2002)
- Instruments 4.3 (4321)
Steps To Reproduce
Open included sample project on each machine.
Make sure the iPhone 4S is selected as the test device.
Select Product > Profile
When Instruments launches, select Time Profiler and continue.
Run the app.
Notice how the symbols are stripped when running on the iMac (Machine 1) but not on the MacBook Air (Machine 2).
Expected Behavior
Symbols from my own code should appear in the Time Profiler on both machines.
Regression
I have tried all of the following, with no change in the actual results:
Rebooting the machine.
Trying other Xcode projects
Deleting the "Derived Data" for all projects in the Xcode Organizer.
Re-symbolicating the document in Instruments (carefully selecting the correct DSYM file in ~/Library/blahBlahBlah…)
Final Notes
Here is a link to a .zip file of a sample project: Sample Project .zip
I was finally able to get it to work by a method that's just shy of a nuke-and-pave scenario:
Make absolutely sure all symbol stripping is disabled for your current build configuration. Make sure you've done this for your Release config if that's what's being profiled for Instruments.
Delete the app from the iOS device.
Restart the iOS device.
Restart the Mac (I don't trust Xcode or Lion at all to quit all relevant processes otherwise).
Launch Xcode, go to Organizer > Projects and delete Derived Data for the affected project.
Clean your project. Hell, why not?
Build and profile for Instruments.
Choose the Time Profiler in Instruments for clarity.
The first run will not show the symbols, but don't quit. Leave Instruments running!
Re-symbolicate the document in Instruments, navigating carefully to the correct dSYM file for the current build. This should be easier since you've deleted the derived data in step 5.
Now you should be able to see your symbols. It helps if you hide non-objective-C symbols.
Why do I suggest that you delete the app and restart the iOS device in Steps 2 and 3? I have a suspicion that Xcode doesn't perform a clean installation of each build, but may install deltas, such that the symbol addresses present in Instruments are a mixture of the current build plus previous builds. If so, then this issue is even more common for someone like me, who shares a single test device between more than one Mac. This assumption could be wildly incorrect.
If the above steps don't work for you, please let me know in the comments. I'd like to create a detailed radar report at some point in the future.
I'm not sure that it has been fixed in the 4.3 but this is a known problem in 4.2 seen here
Instruments
There is a known issue with the Profile action from Xcode 4.2. After a build in which no source files have changed, Instruments will be unable to gather symbols for the target application.
This affects projects where both:
The Release configuration is selected for the Profile action.
(default)
The Strip Linked Product build setting is set to "Yes”, or
a custom Run Script build phase strips the product. (non-default)
The workaround is to do any one of the following:
Perform a "Clean" on the product before initiating the Profile
action.
Do a Clean of the product and temporarily set the Strip Linked
Product build setting to "No" while Profiling.
Set the configuration of the Profile action to Debug.
Run successive profiles directly from within Instruments when you do
not need to rebuild. When developing Mac apps, using the GC Monitor
template in Instruments may cause Instruments to crash. To
workaround the problem please consider migrating your application to
ARC.
I've had a similar problem for days. I was able to profile the Debug configuration, but not Release. First I tried to make a copy of the release configuration (as suggested somewhere on the web), but that copy did not work either.
Then I made a copy of Debug, called it Profile, tried it and the symbols of Profile were shown in the profiler. Great! I then changed the optimization levels etc. to the same as Release, and now it works! Just wanted to share this, as this comment would have spared me hours...
Have been facing the same and stumbled upon this thread.
I realized that I first profiled the app with release build and after changing the scheme in Xcode for the same app, the profiler was still unable to symbolize. I have tried all obvious solutions you mentioned above but in vain.
The profiler somehow is still referring to the first build (release build)'s settings and hence it is not able to symbolize. So, I just changed the app's bundle identifier for testing purpose so that a new app is created altogether for profiling purpose. I could check the code where leaks exist now.
Try it out and let me know if this works for you too. Still pondering over why Instruments is failing to symbolize though.
I had a similar issue where I had no symbols in my os x application that I built from the command line (so in this case it is not an iphone or xcode issue). It turned out the problem was due to a bad DYLD_LIBRARY_PATH that contained my PATH. When I got rid of all those non-library paths, such as /usr/bin/, it worked.
I have a lot of third party frameworks whose symbols and binaries are unfortunately getting lost.
Additionally, my app's binary was getting lost.
I.e. if I selected File > Symbols, clicked my target, and found the similarly named item, the Binary Path was showing up red.
The solution was to go to Instruments > Preferences > Symbols, and add /Users/<MY_USER>/Library/Developer/Xcode/DerviedData to the search paths. Library is not indexed by Spotlight. After doing this, I have at least had the symbols for my app. The little circle next to my app's name goes from Yellow to Green when I do this, and persists between restarting Instruments, unlike other solutions to manually set the binary.
Let me know if you can tell me how to get all the ones for my third party frameworks. I use Carthage for some, others installed manually. Have had no luck with these yet.
I've managed to solve this by:
Disconnecting the device
Deleting the iOS Device Support files for the device's version of iOS in ~/Library/Developer/Xcode/iOS Device Support
Reconnecting the device and letting Xcode reinstall device support.
To be safe I first quit Xcode and Instruments, deleted derived data, and did a clean build as mentioned above, but no need to delete the app or restart any devices this way.
Try open XCode 3 and him Organizer. And try add from this Organizer a devices to both machines.
Just open Organizer and wait him processes. If you're see a button "Use for development" then click him.
Sometimes, XCode 4 can't add a device a truely for full development.

Resources