Reputation: 4173
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?
Upvotes: 3
Views: 2706
Reputation: 95578
The Debug
class provides a lot of useful information about process memory use. You can get information about the Dalvik heap and the native heap. See http://developer.android.com/reference/android/os/Debug.html
Upvotes: 0
Reputation: 12048
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.
Upvotes: 3
Reputation: 4173
Not quite satiscfactory for me, but I've found that ActivityManager.getMemoryClass()
returns amount of memory allocated for application in megabytes.
Upvotes: 1
Reputation: 3412
try the following code:
ActivityManager activityManager = = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
MemoryInfo mi = new MemoryInfo();
activityManager.getMemoryInfo(mi);
Log.i("memory free", "" + mi.availMem);
Upvotes: 2
Reputation: 3412
try the following command:
start the application and enter the following command
C:\Program Files\Android\android-sdk\platform-tools\adb shell dumpsys meminfo "your package name"
Upvotes: 0