使用 1 Mb 堆的奇怪位图 [英] Strange Bitmap using 1 Mb of Heap

查看:17
本文介绍了使用 1 Mb 堆的奇怪位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于好奇,我最近使用 Eclipse 内存分析器测试了我的 Android 应用的内存泄漏.

我遇到了一个大小为 512 x 512 像素的奇怪位图,占用了大约 1 MB 的设备堆内存.

我检查了我的 drawables 文件夹,但找不到该尺寸 (512 x 512) 的位图.

我开始使用谷歌搜索并遇到了这个问题,其中一位用户解释了如何在内存分析器中获取内存泄漏"引用背后的实际图像:

的帮助下以及我个人认为这可能是系统问题的帮助下,我测试了另外两个我的应用.

<块引用>

我测试的两个应用程序也在内存分析器中显示了相同的位图,消耗的字节数完全相同:

此外,我还发现:

<块引用>

位图的来源始终与应用的 LAUNCHER Activity 相关联.

那该怎么办呢?有没有办法摆脱它?

由于我在我的应用中执行内存密集型操作,我希望有尽可能多的可用堆.

解决方案

Android 使用的默认窗口背景是 512x512 图像(您看到的深色主题的蓝深渐变或浅色主题的灰白色渐变).从 Android 4.2 开始,在功能强大的设备上,此图像将替换为程序渐变.

请注意,此位图通常加载在 Zygote 中并由所有应用程序共享.如果转储不排除 Zygote 分配的对象,它可能会出现在堆转储中.

如果您有兴趣,以下是我正在谈论的两个 512x512 背景:

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

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.

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:

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:

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.

解决方案

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

这篇关于使用 1 Mb 堆的奇怪位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆