12

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?

Memory Monitor

device

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76
  • 2
    I would focus instead on `procstats`: http://android-developers.blogspot.com/2014/01/process-stats-understanding-how-your.html – CommonsWare Jan 24 '15 at 20:51
  • In the developer docs Google also has a description on "Investigating RAM Usage" https://developer.android.com/tools/debugging/debugging-memory.html that involves the Android Device Monitor. This can be accessed in Android Studio by going to Tools>Android>Android Device Monitor – Dick Lucas Jan 25 '15 at 18:12

2 Answers2

9

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.

P.T.
  • 24,557
  • 7
  • 64
  • 95
0

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.

Dan Meng
  • 204
  • 2
  • 6