Waypoint
Waypoint

Reputation: 17753

Android - get allocated memory

is there any way, how to determine actual allocated memory in Android application (in code)?

Thanks

Waypoint

Upvotes: 5

Views: 4388

Answers (1)

user370305
user370305

Reputation: 109237

If you talking about Android Application Memory then,

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.

Also you can parse /proc/meminfo command. and get the response for memory information.

EDIT:

ActivityManager activityManager =  (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
Log.i("memory free", "" + memoryInfo.availMem);

For more information look at these two SO questions:

  1. How to discover memory usage of my application in Android
  2. How to get current memory usage in android?

Upvotes: 4

Related Questions