Memory monitor in Android Studio reports different RAM usage than the device

前端 未结 2 1198
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 07:54

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>Andr

相关标签:
2条回答
  • 2021-01-04 08:27

    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.

    0 讨论(0)
  • 2021-01-04 08:28

    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.

    0 讨论(0)
提交回复
热议问题