Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get total RAM size that use Application in Android

I want to gather some statistics from my Android phone.

When I start my application I want to know following:

  • How much RAM does application use.
  • How much free RAM does my phone have.
  • How much total RAM my phone have.

What I must do to gather that statistics, maybe write some code, or maybe you use some applications which give such information or maybe something else. I use MAT but it is not helpful for me maybe I miss something.

The main reason why I want to gather such statistics is that may application start to kill other applications in order to free more space and if I can gather such information I will understand everything.


Edited

For Example my application use library (helper.jar) which size is 85 MB, I know that if application use .jar it loads to the RAM of the phone, now how I can see that my RAM grows from 2 to 2 + 85 (size of .jar).

If I type adb shell cat /proc/meminfo this command from ADB I will see some information about memory.

How I can do same from JAVA code ?


Best Regards, ViTo Brothers.

like image 265
Viktor Apoyan Avatar asked Oct 09 '22 06:10

Viktor Apoyan


1 Answers

If you want to know how much RAM your application can use looks at ActivityManager.getMemoryClass.

There is this limitation on the memory an application can have so that an application cannot steal all memory from other applications. Basically your app shouldn't be able to kill other applications. At least as long as you don't use the option "large heap size" in your app.

The limitation per application is like 16 (on G1) to 48 MB. It depends heavily on the total RAM of your device how much your memory your app can have. The 48 MB for example apply for 1GB RAM.

A method for getting the current memory usage of your app is to look at logcat. It will say something like

GC_CONCURRENT freed 1109K, 12% free 10115K/11463K, paused 5ms+2ms

meaning your program takes uproughly 11 MB of RAM.

like image 145
js- Avatar answered Oct 13 '22 10:10

js-