I am trying to solve some leaks in my Android application.
When on Android Studio, the memory usage returns me <10 MB allocated.
When I look on the tablet application manager, I can see my application is using about 180MB.
I have then used Eclipse memory analyzer. But it also doesn't report a such usage of memory.
I then tried to understand dumpsys meminfo.
I can see most of the memory usage goes into Unknown part of the array displayed (see image below).
Can anyone please tell me what is this Unknown part. Also if anyone have an idea of where the leak can come from looking at the application dumpsys meminfo.
Cheers
Related
When i get memory information using adb shell dumpsys meminfo it shows something called LOST RAM. I know that this equals to TOTAL - FREE RAM - USED RAM but i need to know what this really means.
Is it just a calculation error/issue ? or
Do this amount(LOST RAM) is
really lost because of some hardware or other bug?.
If this is really a bug and not a calculation error so then should i go for a device with low LOST RAM when i'm buying an android device. and should i avoid devices with high LOST RAM value. Please provide me a clear answer for this.
Lost RAM is just RAM that is unaccounted for, it will take all the processes ram usage and add them up the difference between that value and the actual amount of ram left is known as lost ram because the OS can't account for what is using it. It's software related and from what I read can be from ION debug, or drivers that allocate and track their own ram. I don't think it should play any part in your consideration when buying a new android device though.
When investigating RAM usage in an app I am working on, I have been using the Memory Monitor tool in Android Studio (can be accessed in Android Studio by going to Tools>Android>Memory Monitor). I have noticed the RAM usage of my app that is reported in Memory Monitor, is always far lower than when viewing the RAM usage from the device (can be accessed by going to Settings>Apps>Running). As you can see in the screenshots below, Memory Monitor is reporting about 18MB of RAM usage (23MB if you include free space), but the device is reporting 43MB.
Why the difference and also is one more accurate than the other?
I suspect that the memory monitor tool is talking to the dalvik virtual machine about heap allocations made by Java code, and the device manager is showing what the entire process is using for memory. So the first does not include overhead or memory used by the virtual machine itself (or its text and libraries), or any off-heap allocations (sometimes native code can allocate memory that isn't directly visible to the VM).
See https://developer.android.com/tools/debugging/debugging-memory.html#ViewingAllocations and try running the command:
adb shell dumpsys meminfo <package_name>
to get a more precise breakdown of the run-time memory usage of your application.
I've tested the Android Studio's Memory Monitor's Allocated can be get this way programmatically:
long allocatedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
But this only works to get information of the current app.
I'm on a rooted device and want to take a complete memory dump of a certain app.
I've tried:
Some google results say to use "adb kill -10 [pid]"
But, it is giving me "sigusr1 forcing gc (no hprof)", and no hproc is dumped.
This could be device specific.
I've also tried using "Dump PROF file" button in DDMS (Eclipse),
but it only gives me a file that is about 5 MB, this is not a
complete memory dump and not very useful.
I've tried to chmod /proc/[pid]/mem, and access that file, but
even on a rooted device, it is giving me permission denied.
HPROF is a dump of heap alone, so it is obviously not all memory. As explained here, Android no longer dumps heap on SIGUSR1 (signal 10) in newer versions. Some useful facts on using /proc/[pid]/mem are given here. In short: your "permission denied" may as well be caused by trying to read the file in wrong way.
EDIT: to read anything, other than /proc/self/mem having debug permissions may be extra useful, see this question for some insights.
I execute dumpsys meminfo every 2 seconds to sample memory usage of particular Android applications. Sometimes, the application (or even the emulator) crashes while the application is doing dumb things (e.g., rotate the screen back and forth). So, I want to understand how does "executing dumpsys meminfo frequently" affect the state of the whole system.
I have a memory monitoring script that executes dumpsys meminfo a couple times a second and writes the info to a file and it almost never crashes, but I always test using physical devices.
It may be that your emulator just doesn't run fast enough to handle it. Android emulators are incredibly slow.
I have developed a file parsing application on the android platform. How do I check how much memory my application is actually using up ? I tried the adb shell cat /proc/meminfo command but this does not give me how much memory my application is using. it just gives general info about the overall memory. And how much memory should an application typically use up ? what is usual or unusual ? Any help is appreciated. Thanks !
Android apps are constrained to a certain amount of memory. As it's quite (insanely?) low, I think you shouldn't feel guilty about using all of it!
The limit is 16 MB on very old devices, 24 MB or 32 MB on newer ones. There doesn't seem to be much info on the size for different devices, and nobody seems to know why the limit is so small when modern phones have 1-2 GB of RAM.
http://blog.javia.org/how-to-work-around-androids-24-mb-memory-limit/
https://groups.google.com/forum/?fromgroups=#!topic/android-platform/7zKQlrDcypQ
Aha, I found some concrete numbers on the limit:
http://dubroy.com/memory_management_for_android_apps.pdf
G1: 16MB
Droid: 24MB
Nexus One: 32MB
Xoom: 48MB
You can use DDMS > Allocation Tracker to track memory usage and Heap Allocation for your app
http://developer.android.com/resources/articles/track-mem.html
To Track the overall memory of a PID you could use following two methods in ActivityManager
To get a PID of your app :
List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses ()
and then the MemoryInfo
MemoryInfo[] getProcessMemoryInfo (int[] pids)
you might want to take a look at this one. How do I discover memory usage of my application in Android? Or simply try
ActivityManager.getMemoryInfo()
you can check the application memory usage in application mananger, you can check it in the link
You can get the memory usage of your android application with the following command:
Assuming you have adb in PATH:
adb shell dumpsys meminfo com.<your.package>
To see live updation of memory in use, you can try
watch "adb shell dumpsys meminfo com.<your.package>"
Hope this helps