Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - get allocated memory

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

Thanks

Waypoint

like image 655
Waypoint Avatar asked Oct 09 '22 06:10

Waypoint


1 Answers

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?
like image 87
user370305 Avatar answered Oct 12 '22 01:10

user370305