19

I´m developing a very memory-consuming app and want to use the largeHeap-Tag, which should give the application a bit more memory. Whatever I set this tag in AndroidManifest.xml to, it makes no difference to the actual memory I´ve been given. I´m reading out my max memory like this:

Log.v("Utils","Max Mem in MB:"+(Runtime.getRuntime().maxMemory()/1024/1024));

My manifest looks quite like this:

<application android:label="@string/app_name" android:hardwareAccelerated="true" android:largeHeap="true" android:debuggable="true">

    <activity android:name=".EntryActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

I´m running 3.1 in the emulator, output of my logging above is always 48MB. Can somebody help?

matt b
  • 138,234
  • 66
  • 282
  • 345
stk
  • 6,311
  • 11
  • 42
  • 58
  • Not to avoid the question, but what are you using this memory for? – Nick May 20 '11 at 17:07
  • 1
    exactly...if there´s any other way to modify high-res pictures, this would be very welcome. but i didn´t find another way than to work with bitmaps, which are very large. – stk May 20 '11 at 17:47
  • some answers in this good presentation from I/O - http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/en//events/io/2011/static/presofiles/memory_management_for_android_apps.pdf – AlexKorovyansky Sep 16 '11 at 07:04
  • 2
    To Other Users: "largeHeap" option is available only for 3.x tablet android. – Palani Oct 11 '11 at 16:10
  • Just for the record: if you move image processing to the NDK you do not have these artificial Java heap restrictions and can allocate much more memory. – tiguchi Aug 22 '13 at 02:17

2 Answers2

12

Use ActivityManager.getMemoryClass() and ActivityManager.getLargeMemoryClass() to verify the approximated values assigned to your app.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I know this method, but it doesn´t return the actual heap limit value, iirc. it only returns the limits for large or normal heaps, but this is no indicator to whether the limit is now currently standard or large. – stk May 20 '11 at 18:03
  • what are the returned values ? – Diego Torres Milano May 20 '11 at 19:14
  • ah alright...it says that largeHeap in Emulator is the same size as 'normal' heap size...gotta test that on a real device later! – stk May 20 '11 at 20:33
  • on my acer a500, largeheap and normal heap are also the same value. so largeheap seems to be useless in most cases. however, my a500 gives me 256MB for every app, which is quite good. – stk May 26 '11 at 18:47
9

Indeed, the large heap will be the same as normal heap until your app needs more memory for a task. Your VM will display such messages on console:

06-30 15:38:14.770: INFO/dalvikvm-heap(9075): Grow heap (frag case) to 42.365MB for 6152016-byte allocation
06-30 15:38:16.680: INFO/dalvikvm-heap(9075): Grow heap (frag case) to 39.739MB for 3517456-byte allocation
Climbatize
  • 1,103
  • 19
  • 34