Ram consumption in android studio - android

The memory indicator shows:
Max heap size: 1248M
Allocated:986
I have 4gb ram on my syatem.Is there anything I can increase here so that ide becomes a bit faster? I don't use emulator.

There are numerous things which will influence the speed of the IDE, and a few things that you can do to speed it up. In your case having less than the recommended RAM (5GB is officially recommended for 64bit systems), you might find optimising your system gives far more of a performance boost than optimising the IDE itself.
First up, if you are running a Windows OS, the modern versions of which use a lot of RAM (in context of a 4GB system) it might be a good idea to look at installing a light-weight linux distro like Linux Mint. This will free up system resources and give Android Studio more to play with.
Secondly, it is likely your using a web browser along side Android Studio. Browsers, especially when you have multiple tabs open, use a lot of RAM. Use a lightweight browser and be mindful of tab use.
Thirdly, offline mode. One can run Android Studio in offline mode. This will cut some of it's functionality (including code hinting), but will give a performance boost. You can find docs about that here. Enable offline mode with the followings steps (quoted from the documentation):
Open the Preferences window by clicking File > Settings (on Mac,
Android Studio > Preferences).
In the left pane, click Build, Execution, Deployment > Gradle.
Check the Offline work checkbox.
Click Apply or OK.
Since RAM allocation was specifically mentioned, we can take a look at that also.
As mentioned earlier, running windows uses a lot of RAM, so increasing heap memory allocation will unlikely glean any performance gains. It is quite likely you will end up with worse performance, since the JAVA heap will begin eating into RAM required for other system processes.
Also, for each instance of Android Studio, a new java heap will be created, further eating into limited resources (it would best not running multiple instances with 4Gb of memory).
Having said all this, there are some simple ways to edit RAM allocation. As always, be sure to have a look at these docs and these.
For per-project RAM allocation, you can add/edit this line in your gradle.properties:
org.gradle.jvmargs=-Xmx1536m
You can also permenantly edit Java heap allocation by doing the following (taken from the android studio docs):
Click File > Settings from the menu bar (or Android Studio >
Preferences on macOS).
Click Appearance & Behavior > System Settings > Memory Settings.
Adjust the heap sizes to match your desired amounts.
Click Apply.

Related

Android Studio Profiler shows 100 MB of memory usage for empty activity

I'm using Android Studio Profiler to check and optimize memory consumption. to do some tests, I have disabled every section in the app except for the main activity. so when the app launches, there is only a blank activity which does not do anything and does not hold any view. then when I run the profiler, it shows about 100 MB of memory is being used by my app, half of which is for native code.
Moreover, when I dump the heap, it shows only 6.3 MB of retained size. these numbers confuse me! how and why such large amounts of memory (100 MB) are being used while my activity is empty and not doing any task?
The screenshot shows the app heap is about 6.3 MB. There may be other heaps (clicking the "View app heap" menu). Those heaps combined are what the JVM is using, which should be consistent with the "Java" category from the profiler's timeline.
To find out what native memory is used for, it may be helpful to try Android Studio's native memory profiler during app startup.
When the profiler is used with a debuggable process, it will do things behind the scene, such as attaching a JVMTI agent. Those operations will occupy native memory. To eliminate those noise, please consider using a profileable build. Here is the instruction to build a profileable app, and you need Android Studio Bumblebee to view profileable processes in the profiler.

Android: Where's the Memory Monitor tool?

There is a tool Memory Monitor to analyze the memory allocation as time goes by, the figure it generates like below:
I just cannot find the tool like "Memory Monitor". Where can i find it?
Since this tool location seems to have changed over time (as the Android Monitoring suite of tools grows), here's a breakdown for selected Android Studio versions (if you want to add a version that's missing, feel free to suggest an edit to this answer to include it!)
Android Studio 2.2.3
IDE access (bottom left, now grouped with other monitors in the Monitor tab):
Menu access:
View -> Tool Windows -> Android Monitor
Android Studio 2.0 Preview
IDE access (bottom left):
Menu access:
View -> Tool Windows -> Android Monitor
and then select the Memory tab.
Android Studio 0.8.10
IDE access (bottom right):
Menu access:
Tools -> Android -> Memory Monitor
or
View -> Tool Windows -> Memory Monitor
In the latest Android Studio version (i'm using the Canary channel) ver 1.3 the Memory Monitor is located under the Android tab at the bottom --> memory.
In the latest version (1.4.1) of Android Studio, it shows on the bottom, but you have to activate it, at least I needed to activate it by going to Tools > Android > Enable ADB Integration as in the following image:
I.e., there is no "Memory Tool" in the Tools > Android menu, as it is directly visible in the bottom left of the screen.
Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more. This page provides a modest discussion of DDMS features; it is not an exhaustive exploration of all the features and capabilities.
Viewing heap usage for a process
DDMS allows you to view how much heap memory a process is using. This information is useful in tracking heap usage at a certain point of time during the execution of your application.
To view heap usage for a process:
In the Devices tab, select the process that you want to see the heap information for.
Click the Update Heap button to enable heap information for the process.
In the Heap tab, click Cause GC to invoke garbage collection, which enables the collection of heap data. When the operation completes, you will see a group of object types and the memory that has been allocated for each type. You can click Cause GC again to refresh the data.
Click on an object type in the list to see a bar graph that shows the number of objects allocated for a particular memory size in bytes.
DDMS Android Documentation

Xamarin Android: How to increase max jdk memory for layout renderer in Visual Studio

I'm developing a rather complex user interface in Xamarin Android for Visual Studio 2012. There are four versions of this interface, Normal, Small, Large and Landscape. When I added the Landscape layout (the last one), the JDK that runs the renderer run up to 890 Mb usage and I assume is thrashing the garbage collector as it's using 50% of the CPU on a quad-core system. Sometimes the layouts will load, but more often I get a blank white box in the middle of the layout and have to shut down both visual studio and kill the jvm that's run amok.
Is there a way to tell the SDK to use 2G of memory instead of 1G for the renderer?
In Visual Studio, you can now go to:
Project Properties > Android Options > Advanced (tab) > Java Max Heap Size
2g will give you 2GB

Android studio using > 100% CPU at all times - no background processes appear to be running

I've noticed Android Studio (when running) uses greater than 100% CPU at all times, even when it appears there are no background processes that the IDE is running (indexing, etc). I might suspect this were something specific to my box, but some fellow developers are encountering this as well.
Often times the CPU usage is in the high 100s or mid 200s (see screenshots below). Has anyone encountered this as well? If so, are there any strategies or options within the IDE to correct this intensive use of system resources?
Thanks to Buzzrick (answered on this page, probably above my answer), he mentioned about VCS. Turning off all of the background operations of VCS seemed to have a HUGE impact toward the high cpu usage - it was 150% and now it's 20%, more or less.
I'm on OS X
Go to: Preferences > Version Control > Background. Now listed under 'Background Operations' are 6 options.
I disabled the first three options which are:
Perform update on VCS in background,
Perform commit to VCS in background,
Perform checkout to VCS in background.
You can try the following options in the File Menu:
File Menu -> Invalidate Caches / Restart... -> Invalidate and Restart
Enable Power Save Mode by clicking on File -> Power Save Mode
Power Save mode only disable code insights and background tasks.
You might consider going to File > Invalidate Caches / Restart
Your cache might be kicking off something funky in the background
I encountered a constant high cpu usage with no apparent reason. Invalidating cache did not work nor did the power save mode.
In my case there was a something wrong in the '.git' directory which was causing android studio to fail in an endless loop. Checking out the repo again fixed the problem.
My advice is to check the android studio logs for any hints to what is causing it to falter. You could also start it from terminal and check the Stdout/Stderr output.
I switched on power save in Android Studio 1.0 it helped but this meant I opted out on so many features that Android Studio has to offer. Thus I sought to find a better solution, I happened to always have a dialog box pop up and ask me to increase my VM size. Apparently once I increased this, I am able to switch off power save and have my Android Studio work perfectly.
This is how to do so:
On Mac OS go to /Applications/Android\ Studio.app/Contents/bin/studio.vmoptions (To open contents right click on Android Studio app > View contents)
You will find the following variables
-Xms128m
-Xmx4096m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=200m
-XX:+UseCompressedOops
On Windows go to Environment Variables and find a System Variable called _JAVA_OPTIONS
Increase these figures accordingly.
Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM).
Xms specifies the initial memory allocation pool.
i.e Your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory.
I had exact same problem on Linux. Solved by increasing the memory size.
Started by looking at the top -p <android studio pid> -H which shows which threads are using most of CPU, to me there are three threads: 94232,94233,94234. Then I do a jstack <pid> to get the stack dump of android studio, and look for 0x17018 (=94232), it turns out to be "Gang worker#0 (Parallel CMD Threads)". All three of them. apparently JVM is too busy doing GC all the time.
Also opened jconsole against my android studio process and it shows GC time "20 minutes"!!! (at the bottom of memory tab)
Fix is to change the studio.vmoptions (or studio64.vmoptions in my case), to increase the -Xmx value from default 750m to 1500m. It is sufficient for me. if you have too much memory, set to 2g or 4g or 16g..
Interestingly, for me this seemed to be something to do with the version control integration.
I fixed this by re-loading my android studio project and when it asked about wiring up my CVS links (I don't recall the exact wording), I just said "Ignore". After that it ran smoothly without pulling CPU
I tried the following procedure and Android Studio on my Surface Pro 3 sped up by an insane amount:
Reduce the amount and memory of the Android Virtual Devices you have.
Invalidate Caches/Restart
Go to Power Save Mode
Close all unnecessary files that are opened.
Reduce your VM Heap Size to around 256.
On Windows I reduced the studio64.exe process priority and set the process' affinity to half of the cores.
Open Task Manager, click on Processes tab, right click on process studio64.exe and you'll see it in the menu.
I've left this question open for awhile as coworkers and posters here have found value in various solutions over time. For myself, simply updating Android Studio solved the issue (after a number of months where none of the solutions herein worked for me).
In my case I have white-listed Android-Studio's folder in "Eset Smart Security" and the problem solved!
hope this helps!
Edit:
Disabling HIPS in Eset settings was also helpful in my situation!
You can check which part of Android Studio or which plugin is using a lot of CPU, with Android Studio -> Help -> Diagnostic Tools -> Activity Monitor
On Android Studio 2.3, this used to happen when the "Android Monitor" window was open (the window shows Logcat messages from devices and emulators), and then you press Ctrl+F (Cmd+F on the Mac) to reveal the 'Find' search bar inside this window.
It can also happen when you connect a Samsung phone to your computer via USB, which has Developer Mode enabled, because Samsung phones usually send out large amounts of debug text to Logcat every second, even if the Logcat window is closed.
So the solutions to prevent the 100% CPU usage are either:
Turn off the Find search bar, or hide the window completely. Or ...
Disconnect a Samsung phone which is sending out lots of debug messages. Or ...
Upgrade to Android Studio 3, where this bug doesn't happen. Or ...
If all else fails, just restart Android Studio

Bad perfomance with Android plugin for Eclipse

When dimensions of a project start being considerable the plugin of Android for Eclipse starts not working properly and also very slow, when it comes to XML modifications, refractoring the code from the XML files becomes tedious. Also sometimes it doesnt recognize strings resources. And I have to clean the project(which sometimes is like the solution for windows of restart the computer...)
Do you know about solutions to improve this behaviour? As I think it will be really helpful.
There are two things impacting eclipse's performance: I/O and memory....
I/O: Buy Good SSD disk. Full stop.
Memory:
There are few ways to improve performance:
1) include the following lines in eclipse.ini (with at least these values):
-vmargs
-Xms160m
-Xmx2048m
(that is if you have enough memory)
2) Use 32-bit eclipse on 64-bit system
That might be surprising, and it is only valid if you have not very big amount of memory (few gigs). 32-bit eclipse take about 50-60% of memory comparing to 64-bit one - the thing is that in 64-bit java every object/field etc. take 2x much memory as in 32-bit java. Until java supports (so far experimental) compressed references taking less space, it might well be that memory limits will be hit with 64-bit version where 320bit should work just fine.
Eclipse can run slow if you have too many projects open, especially if the projects are very large. I remember when i had like 3 sample projects open at the same time and eclipse went from running on 200 meg to running at 500 meg, it was really slow untill i closed all the projects i wasnt using, it also depends which type of computer you have, if your computer doesnt have very much ram then eclipse will run slow. My computer cleans projects really slow when i have a bunch of projects open.
Please make sure that eclipse.ini doesn't contains following line:
CompileThreshold=5
I have taken this line from some superfast Eclipse jvm config, but that option just makes compilation terribly slow.

Categories

Resources