Maximum memory limit of each Process in Android

Android is a full multitasking system so it’s possible to run multiple programs at the same time and obviously each one can’t use all of your device memory.
For this reason there is a hard limit on your Android application’s heap size: if your application needs to allocate more memory and you have gone up to that heap size already, you are basically going to get “out of memory error”.
Heap size limit is device dependent and it has changed a lot over the years, the first Android phone (the G1) has 16MB heap size limit, now we have devices which have 32 MB / 48MB/ 64 MB/ 192 MB/ 512 MB heap size limit.
The basic reason is that new tablets and new phones have an high monitor resolution so they need more memory in order to draw more pixels.
However this limit is also too tight for a new kind of application. For example, think about a photo editor that is really memory intensive, probably 48MB of heap space isn’t enough for that.
For that kind of application Honeycomb and later introduced an option in the Android Manifest: “android:largeHeap=true” that give you a big heap space limit.
You have to use this option only if you are going to build an application that is really memory intensive and you really need it.

long maxMemory = Runtime.getRuntime().maxMemory();
System.out.println("Max Memory: " + maxMemory);

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.

Leave a comment