Search code examples
androidandroid-4.2-jelly-bean

Very high memory consumption on Nexus 7 with Android Jelly Bean


I have an application which is quite memory consuming - handling large bitmaps. I have tuned the application using well known techniques for handling such bitmaps (please no links on tutorials in answers...) so that it runs fine without any OutOfMemoryError exceptions, but only on devices running HC and ICS, on Jelly Bean the same application has almost 80 % higher memory consumption, which leads to bad user experience, the app is lagging and slow.

I prepared a simple test, just created the simplest Android application using a template in Eclipse; the app has only one activity with a background bitmap (1280 x 800). On device with Android 3.1 (Asus A500) it allocates:

01-23 12:28:02.402: D/dalvikvm(31706): GC_FOR_ALLOC freed 65K, 4% free 6559K/6787K, paused 17ms
01-23 12:28:02.402: I/dalvikvm-heap(31706): Grow heap (frag case) to 10.355MB for 4096016-byte allocation
01-23 12:28:02.432: D/dalvikvm(31706): GC_CONCURRENT freed 1K, 3% free 10558K/10823K, paused 1ms+2ms

On Nexus 7 with JellyBean 4.2.1 it allocates:

01-23 12:13:49.740: D/dalvikvm(23815): GC_FOR_ALLOC freed 84K, 4% free 7464K/7700K, paused 18ms, total 18ms
01-23 12:13:49.750: I/dalvikvm-heap(23815): Grow heap (frag case) to 11.338MB for 4096016-byte allocation
01-23 12:13:49.770: D/dalvikvm(23815): GC_FOR_ALLOC freed 1K, 3% free 11463K/11704K, paused 23ms, total 23ms
01-23 12:13:49.800: D/dalvikvm(23815): GC_CONCURRENT freed <1K, 3% free 11463K/11704K, paused 2ms+2ms, total 23ms
01-23 12:13:49.900: D/dalvikvm(23815): GC_FOR_ALLOC freed <1K, 3% free 11463K/11704K, paused 12ms, total 13ms
01-23 12:13:49.920: I/dalvikvm-heap(23815): Grow heap (frag case) to 18.259MB for 7259056-byte allocation
01-23 12:13:49.940: D/dalvikvm(23815): GC_FOR_ALLOC freed 0K, 2% free 18552K/18796K, paused 16ms, total 16ms
01-23 12:13:49.960: D/dalvikvm(23815): GC_CONCURRENT freed <1K, 2% free 18552K/18796K, paused 3ms+2ms, total 17ms

So I have two questions:

1, why the application consumes so much memory when using only one bitmap on the background of its main activity?

2, why the device with JellyBean has almost 80 % higher memory consumption when running the same application?

EDIT1:

All devices have the same screen resolution: 1280 x 800 px


Solution

  • I am running into the same thing - Unfortunately I suspect it is caused by the fact that the latest versions of android will try and use the 3d accelerator as much as possible - they will take a copy of your image and pass it onto the 3d accelerator when is then used for rendering the actual pixels that the user sees. This is why you are seeing higher memory consumption.

    As for what can be done about it - unfortunately not much. This higher memory usage results in an overall much smoother UI (This is project butter, which came along in android 4.1). If you have already looked into the various tutorials such as googles displaying bitmaps efficiently then all I can suggest is try turning on largeHeap in the application element of the manifest - thats what worked for me.

    Additionally depending on how you app works, it may be possible to recycle bitmaps. This DevBytes video from google explains how.