Skip to content

Max heap size for an Android application


Max heap size for an Android application is 16MB.
When the heap size reaches above 16MB, you will get an java.lang.OutOfMemoryError exeption.


To detect low memory, Use Activity.onLowMemory()

To get memory information, use ActivityManager.MemoryInfo or Debug.getNativeHeapSize()

Without modifying system property, there is no way to increase max heap size.


strcpy(heapsizeOptsBuf, "-Xmx");
property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
//LOGI("Heap size: %s", heapsizeOptsBuf);
opt.optionString = heapsizeOptsBuf;

public void recycle ()
Since: API Level 1

Free up the memory associated with this bitmap’s pixels, and mark the bitmap as “dead”, meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing. This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the bitmap. This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.

One Comment leave one →
  1. John Ulmer permalink
    04/15/2012 20:53

    Heap size is actually device-dependent and nowadays can vary from 16MB to 48MB. See Patrick Dubroy’s Google I/O talk for details.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: