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:
- The young generation stores short-lived objects that are created and immediately garbage collected.
- 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.
- 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.
- 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 http://dwij.co.in/category/snippets