Memory usage between Android 2.2 and 2.3

I am developing an application containing many images. I noticed that the memory usage of my application in Android 2.3 is slightly higher than in Android 2.2 - ultimately lead to OutOfMemory errors while loading bitmap images. Studying this, I recorded the result of Debug.getNativeHeapAllocatedSize () in the onResume of the first Event. In Android 2.2, this outputs 5 MB. In Android 2.3, these are 17 MB outputs.

I created a sample application to try to further narrow it down. The sample application has 2 actions: the first has a small image and to launch the second action; The second action has slightly larger images in ScrollView. You can download the sample here: http://dl.dropbox.com/u/21709517/MemoryUsageExample.zip When you run this example, the 3 MB Debug.getNativeHeapAllocatedSize () reports allocated after the start of the first action in both 2.2 and 2.3. After launching the second event, Android 2.2 still reports 3 MB allocated, while Android 2.3 reports 17 MB allocation. Running "adb shell dumpsys meminfo test.example" shows the same types of results.

Why is there such a dramatic difference between Android 2.2 and 2.3? And more importantly, what should I do differently so that using so much memory on Android 2.3?

----- ----- UPDATE

Looking at the information published by Romain Guy, I decided to play a little with various download options. The result shows that forced image downloads, since RGB_565 really reduces memory in Android 2.3, however it still uses over 2.2. In my example, the Android 2.3 application now uses 10 MB versus Android 2.2 using 3 MB. In addition, I tried to force 32-bit to use ARGB_8888. In this case, Android 2.3 uses 17 MB, but Android 2.2 continues to use only 3 MB. An updated sample can be found here: http://dl.dropbox.com/u/21709517/MemoryUsageExample2.zip

What is the reason for these differences? Does more need to be done to use memory for Android 2.2? Also, is there a way to force images created using XML layouts in a specific format? Can this be installed for the entire application? Thanks.

----- UPDATE 2 -----

According to this thread, it is not possible to force images loaded using xml inflation to be a specific format.

I still hope to get an answer to the question why Android 2.2 and Android 2.3 use different amounts of memory after forcing 16 or 32 bits.

+7
source share
2 answers

Android 2.3 downloads 32-bit images by default. You can format the 16-bit format using BitmapFactory.Options.

See http://www.curious-creature.org/2010/12/04/gingerbread-and-32-bits-windows/ and http://www.curious-creature.org/2010/12/08/bitmap -quality-banding-and-dithering /

+6
source

My guess is this. Android OS preloads some images in a bunch. The number of preloaded images depends on the budget of the VM OS for each process. Since 2.3 increased the VM budget to 32M, so he preloaded more images for each process than on 2.2 devices. Consequently, you have seen wider use of the heap in 2.3. This is just my guess.

0
source

All Articles