How to increase heap size of an Android Application

What is Heap

The Java virtual machine heap is the area of memory used by the JVM, specifically HotSpot, for dynamic memory allocation.
The heap is divided into generations:

  1. The young generation stores short-lived objects that are created and immediately garbage collected.
  2. Objects that persist longer are moved to the old generation (also called the tenured generation).

The permanent generation (or permgen) is used for class definitions and associated metadata. Permanent generation is not part of the heap. See diagram below:


How to increase heap size

Sometimes when we use so many images & backgrounds in applications, it takes lot of space on android RAM. This leads to force close your application by “Out of memory Bound Exception”. To solve this problem you just need to increase the heap size allocated to your Application. This can be done by two ways according to your Android OS.

  1. You can use android:largeHeap="true" in application tag of Android manifest(Reference here) to request a larger heap size, but this will not work on any pre Honeycomb devices.
  2. On pre 2.3 devices, you can use the VMRuntime class, but this will not work on Gingerbread and above See below how to do it.

Before Setting HeapSize make sure that you have entered the appropriate size which will not affect other application or OS functionality. Before settings just check how much size your app takes & then set the size just to fulfill your job. Dont use so much of memory otherwise other apps might affect.

See more such snippets on

Ganesh Bhosale

From a laptop to a full organization, Ganesh has traveled a tough road. A commando, armed with the latest tech & a huge warehouse of knowledge, he leads by example & is here for the long haul. His strong belief in giving back more has borne rich fruits, both for his employees & clients.

You may also like...

1 Response

  1. Pamela says:

    How can this be achieved in devices running android 2.3?

Leave a Reply

Your email address will not be published. Required fields are marked *