How to get the amount of free memory of current running process on android? Or how to get the total amount of memory allocated to current process programmatically?
Method ActivityManager.getMemoryInfo() doesn't work in my case because it returns free SYSTEM memory, but not the process memory. There's also ActivityManager.getProcessInfo() method but it returns an old API struct and I don't know whether it's possible to retrieve amount of free memory using that data.
Any explanations on that methods or maybe some other ways to get the amount of free memory?
You can also use Runtime.getRuntime().maxMemory(); which returns the maximum heap size for your process in bytes.
Althoug this is usually the same as memory class, I've found situations when memory class returns a higher value (i.e. 24MB) and heap size returns a lower value (i.e. 16MB), and the value realy available for the processs is the lower one.
try the following code:
ActivityManager activityManager = = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
activityManager.getMemoryInfo(mi);
Log.i("memory free", "" + mi.availMem);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With