Android-获取分配的内存 [英] Android - get allocated memory
问题描述
有什么方法,如何确定Android应用程序中实际分配的内存(以代码形式)?
is there any way, how to determine actual allocated memory in Android application (in code)?
谢谢
Waypoint
推荐答案
如果您谈论的是Android应用程序内存,
If you talking about Android Application Memory then,
ActivityManager.getMemoryInfo()
是我们用于查看整体内存使用情况的最高级别的API.
ActivityManager.getMemoryInfo()
is our highest-level API for looking at overall memory usage.
Going lower-level, you can use the Debug API to get raw kernel-level information about memory usage.
Note starting with 2.0 there is also an API, ActivityManager.getProcessMemoryInfo
, to get this information about another process.
还可以解析/proc/meminfo
命令.并获取内存信息的响应.
Also you can parse /proc/meminfo
command. and get the response for memory information.
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
Log.i("memory free", "" + memoryInfo.availMem);
有关更多信息,请查看以下两个SO问题:
For more information look at these two SO questions:
- How to discover memory usage of my application in Android
- How to get current memory usage in android?
这篇关于Android-获取分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!