Android-获取分配的内存 [英] Android - get allocated memory

查看:230
本文介绍了Android-获取分配的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法,如何确定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.

请注意,从2.0开始,还有一个API,

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:

  1. 如何在以下位置发现我的应用程序的内存使用情况Android
  2. 如何获取android中的当前内存使用情况?
  1. How to discover memory usage of my application in Android
  2. How to get current memory usage in android?

这篇关于Android-获取分配的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆