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.
frameworks/base/core/jni/AndroidRuntime.cpp
AndroidRuntime::startVm()
...
strcpy(heapsizeOptsBuf, "-Xmx");
property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m");
//LOGI("Heap size: %s", heapsizeOptsBuf);
opt.optionString = heapsizeOptsBuf;
mOptions.add(opt);
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.
