Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much memory does each android process get?

Tags:

android

memory

Can we rely on our Android app getting a set amount of memory or does it vary between phone models or OS versions?

For example, I have a memory cache, and I've set its limit to 5 MB. If on one device, my app will only get 8 MB of memory to play with, and on another, 24 MB, I'd like to tune the cap of the memory cache to take advantage of more or less memory.

Is there any way to figure this out, does the amount even vary?

like image 808
user291701 Avatar asked May 25 '12 00:05

user291701


1 Answers

Yes, the maximum heap size varies from device to device. You can check the device's approximate per-application memory class by calling getMemoryClass().

Returns the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.

The only built-in way to change heap size of an app is by setting android:largeHeap="true" in the AndroidManifest.xml. This will generally increase heap size from 48 to 128. Keep in mind this approach will only work on 3.x tablets. Otherwise, you'll need a rooted device, which is obviously not something you would want to rely on as a developer.

like image 149
Alex Lockwood Avatar answered Oct 11 '22 12:10

Alex Lockwood