5

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

Thanks

Waypoint

Waypoint
  • 17,283
  • 39
  • 116
  • 170
  • Waypoint,see this ans may be helpful [Read android device total ammount of ram with /proc/meminfo](http://stackoverflow.com/questions/9869761/read-android-device-total-ammount-of-ram-with-proc-meminfo/9870018#9870018) – ρяσѕρєя K Mar 29 '12 at 05:52
  • 1
    I am getting only total ammount of RAM, I need actual use by my application – Waypoint Mar 29 '12 at 09:51
  • run this command `Runtime.getRuntime().exec("/system/bin/top -n 50");` this will give u all processes info and then parse it – ρяσѕρєя K Mar 29 '12 at 10:00
  • Waypoint, see this post :[How to discover memory usage of my application in Android](http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android) – ρяσѕρєя K Mar 29 '12 at 10:06

1 Answers1

4

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?
Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • Thanks but what mehotd of ActivityManager.getMemoryInfo() exactly? Noone seems to be fir for me – Waypoint Mar 29 '12 at 05:26
  • Thanks for your edit, I cannot parse proc/meminfo so I tried to use ActivityManager.getMemoryInfo but it shows only availMem. Nevertheless I load fields or not, availMem is not changing – Waypoint Mar 29 '12 at 05:42
  • In this question http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android use /proc/meminfo file for get memory info. – user370305 Mar 29 '12 at 05:46
  • 1
    /proc/meminfo is giving me only maximum RAM size, i need actual allocated size – Waypoint Mar 29 '12 at 09:52