Skip to content

Max heap size for an Android application

10/11/2010

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

avoiding-memory-leaks

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.

Advertisement
No comments yet

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.