
1. 该代码获取当前应用程序的内存使用情况
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
//最大分配内存
int memory = activityManager.getMemoryClass();
System.out.println("memory: "+memory);
//最大分配内存获取方法2
float maxMemory = (float) (Runtime.getRuntime().maxMemory() * 1.0/ (1024 * 1024));
//当前分配的总内存
float totalMemory = (float) (Runtime.getRuntime().totalMemory() * 1.0/ (1024 * 1024));
//剩余内存
float freeMemory = (float) (Runtime.getRuntime().freeMemory() * 1.0/ (1024 * 1024));
System.out.println("maxMemory: "+maxMemory);
System.out.println("totalMemory: "+totalMemory);
System.out.println("freeMemory: "+freeMemory);
结果

System.out: memory: 256 System.out: maxMemory: 256.0 System.out: totalMemory: 11.974937 System.out: freeMemory: 3.6257935
这表明我的应用程序在当前手机上的最大分配内存为256m,现在已分配11m,而11m中的6m是免费的
当然,您可以通过Monitors更直观地查看内存使用情况

2. 使用dos命令
(1)打开dos窗口并执行adb shell
(2)dumpsys meminfo软件包名称

结果:

3. 使用显示器或DDMS


显示器

DDMS
以上是本文的全部内容,希望对大家的学习有所帮助,并希望您能更多地支持Scripthome.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shoujiruanjian/article-312782-1.html
以身作则