How do you programmatically detect the application heap size available to an Android app?
I heard there's a function that does this in later versions of the SDK. In any case, I'm looking for solution that works for 1.5 and upwards.
How do you programmatically detect the application heap size available to an Android app?
I heard there's a function that does this in later versions of the SDK. In any case, I'm looking for solution that works for 1.5 and upwards.
Do you mean programatically, or just while you're developing and debugging? If the latter, you can see that info from the DDMS perspective in Eclipse. When your emulator (possibly even physical phone that is plugged in) is running, it will list the active processes in a window on the left. You can select it and there's an option to track the heap allocations.
Debug.getNativeHeapSize()
will do the trick, I should think. It's been there since 1.0, though.
The Debug
class has lots of great methods for tracking allocations and other performance concerns. Also, if you need to detect a low-memory situation, check out Activity.onLowMemory()
.
This official API is:
http://developer.android.com/reference/android/app/ActivityManager.html#getMemoryClass()
This was introduced in 2.0 where larger memory devices appeared. You can assume that devices running prior versions of the OS are using the original memory class (16).