What are advantages of setting largeHeap to true?

Intsab Haider picture Intsab Haider · Dec 10, 2014 · Viewed 86.5k times · Source

I have an application with large number of classes & also many libraries are included, I am setting android:largeHeap="true" as i am getting memory issue, My Manifest file code is attached.

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="My Huge Application"
        android:largeHeap="true"
        android:logo="@drawable/logo"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" >
</application>

I had to ask that is this a good practice? Kindly suggest advantages and disadvantages (pros and cons) of using it.

Answer

Mightian picture Mightian · Jun 19, 2015

Way too late for the party here, but i will offer my 0.02$ anyways.
It's not a good idea to use android:largeHeap="true" here's the extract from google that explains it,

However, the ability to request a large heap is intended only for a small set of apps that can justify the need to consume more RAM (such as a large photo editing app). Never request a large heap simply because you've run out of memory and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. Yet, even when you're confident your app can justify the large heap, you should avoid requesting it to whatever extent possible. Using the extra memory will increasingly be to the detriment of the overall user experience because garbage collection will take longer and system performance may be slower when task switching or performing other common operations.

here's the complete link of the documentation https://developer.android.com/training/articles/memory.html

UPDATE

After working excrutiatingly with out of memory errors i would say adding this to the manifest to avoid the oom issue is not a sin, also like @Milad points out below it does not affect the normal working of the app

UPDATE 2

Here are a few tips to deal with out of memory errors

1) Use these callback that android gives onLowMemory, onTrimMemory(int) and clear the cache of image like (picasso, glide, fresco....) you can read more about them here and here
2) compress your files(images, pdf)
3) read about how to handle bitmap more efficiently here
4) Use lint regularly before production pushes to ensure code is sleek and not bulky