14

I've got a Galaxy Nexus myself, and I know that the android:largeHeap="true" manifest option works on this phone, but I was wondering if it's working on older phones that are being upgraded to Ice Cream Sandwich, i.e. the Samsung Nexus S.

The reason why I'm asking is that I've built an application that makes heavy use of large bitmaps and the application was originally designed for tablets with 48 MB of heap size. The Galaxy Nexus also features 48 MB of available heap size for each application, so my application is working beautifully on this phone despite it not being a tablet.

The problem is that the Nexus S only has 32 MB of heap available, so I really need the large heap option for the application to work on these older phones with ICS.

My question: Does the android:largeHeap option still increase the of available heap memory? I.e. if the Nexus S has 32 MB by default, will I be able to access perhap 64 MB available by using this?

For those of you unfamiliar with this option, it increases the amount of available heap memory for your application at the cost of lower performance. It should only be used when there's no other alternative.

Update

Here's the application package to show your available heap size: http://michellbak.dk/TestHeapSize.apk

The source code is below to show you that there's nothing harmful:

package com.miz.heapsize;

import android.app.Activity;
import android.app.ActivityManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView text;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ActivityManager am = ((ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE));
        int memory = am.getMemoryClass();
        int largeMemory = am.getLargeMemoryClass();

        text = (TextView) findViewById(R.id.textView1);
        text.setText("Normal heap size: " + memory + "\nLarge heap size: " + largeMemory);

    }
}

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.miz.heapsize"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true" >
        <activity
            android:label="@string/app_name"
            android:name=".MainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Michell Bak
  • 13,182
  • 11
  • 64
  • 121

1 Answers1

18

The android:largeHeap option is available on all devices running Android 3.0 or above. This includes devices that have been upgraded to ICS.

That said, you're not guaranteed to get 48 MB of space. The exact heap size provided to applications is an option device manufacturers can set on a per-device basis. In general, devices with a larger display will be configured with larger heap sizes.

Trevor Johns
  • 15,682
  • 3
  • 55
  • 54
  • Yeah, the Nexus S will by default only give you 32 MB of heap memory, but the `android:largeHeap` option should double the amount of available heap memory, so my question is whether or not this works on older devices that are upgraded to ICS. – Michell Bak Dec 30 '11 at 01:02
  • The flag works. What you'll get by enabling that flag is not as clearly defined. ;) Like @CommonsWare suggested, let's try it and see what happens! Unfortunately I left my Nexus S in the office, but if nobody gets to it first I can try it the next time I'm in. – Trevor Johns Dec 30 '11 at 01:06
  • +1. Thanks, Trevor. Much appreciated :) Mark more or less just answered my question in the comments, so I hope you don't mind me accepting that if he adds it as an answer. If not, I'll accept yours. Cheers! – Michell Bak Dec 30 '11 at 01:08
  • I don't mind at all. Mark's answers are usually better than mine anyway. ;) – Trevor Johns Dec 30 '11 at 01:11