Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

android - Strange Bitmap using 1 Mb of Heap

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...