14
votes

Out of curiosity, I just recently tested my Android App for Memory Leaks, using the Eclipse Memory Analyzer.

I came across a strange Bitmap with the size of 512 x 512 pixels using up about 1 Megabyte of my devices heap memory.

enter image description here

I checked my drawables folder and could not find a bitmap of that size (512 x 512).

I started googling and came across this question, where a user explains how to get the actual Image behind a "memory leak" reference in the Memory Analyzer:

MAT (Eclipse Memory Analyzer) - how to view bitmaps from memory dump

I followed the tutorial and with the help of GIMP, I extracted the following Image:

enter image description here

So my questions are:

  • What is that?
  • What is it doing in my applications heap?
  • How do I get rid of it?
  • Does anyone else have the same bitmap in his heap?

Notes:

  • In my drawables folder is no Bitmap looking like that
  • The largest Bitmap my app uses is 140 x 140 pixels
  • I have a feeling that this Bitmap somehow comes from the system
  • The Bitmap is in heap right after app start - without any user interaction
  • I am debugging on a HTC One S, Android 4.1 Cyanogen Mod (Screen 540 x 960)
  • I am not using external Libraries

Update:

With the help of Selvin's suggestion and my personal felling that this could be a System-issue, I tested two other apps of mine.

Both of the apps I tested also showed the same Bitmap in the Memory Analyzer with exactly the same amount of bytes consumed:

enter image description here

Furthermore, I was able to find out that:

The source of the Bitmap is always associated with the LAUNCHER Activity of the app.

So what to do about that? Is there a way to get rid of it?

Since I do memory-intensive operations in my app, I'd like to have as much heap available as possible.

1
Maybe it exists in one of the libraries included in your app's build path, if any.Ali Alnoaimi
Good idea, but I have no libraries included in my project.Philipp Jahoda
just my 2 cents: at your place i'll would check if other project(fx.: new one) will have the same Bitmap, too ... if so, your assumption: I have a feeling that this Bitmap somehow comes from the system will be true and i'll stop worry about this :)Selvin
I will check that and report back, thank you.Philipp Jahoda
I also have a strange 1MB Bitmap in the heap. It seems every application has it.vortexwolf

1 Answers

17
votes

The default window background used by Android is a 512x512 image (the blueish-dark gradient you see with the dark theme or the gray-white gradient with the light theme). On capable devices, this image is replaced with a procedural gradient as of Android 4.2.

Note that this bitmap is normally loaded in Zygote and shared by all the apps. It might show up in heap dumps if the dump doesn't exclude Zygote-allocated objects.

Here are the two 512x512 backgrounds I'm talking about if you're interested:

https://github.com/android/platform_frameworks_base/blob/jb-mr0-release/core/res/res/drawable-nodpi/background_holo_dark.png

https://github.com/android/platform_frameworks_base/blob/jb-mr0-release/core/res/res/drawable-nodpi/background_holo_light.png