gpt4 book ai didi

android - 使用 1 Mb 堆的奇怪位图

转载 作者:可可西里 更新时间:2023-11-01 19:05:18 25 4
gpt4 key购买 nike

出于好奇,我最近使用 Eclipse Memory Analyzer 测试了我的 Android 应用程序是否存在内存泄漏。

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

enter image description here

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

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

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

我按照教程并在 GIMP 的帮助下提取了以下图像:

enter image description here

所以我的问题是:

  • 那是什么?
  • 它在我的应用程序堆中做什么?
  • 如何摆脱它?
  • 其他人的堆中是否有相同的位图?

注意事项:

  • 在我的 drawables 文件夹中没有像那样的位图
  • 我的应用使用的最大位图是 140 x 140 像素
  • 我有一种感觉,这个位图不知何故来自系统
  • Bitmap 在应用程序启动后立即在堆中 - 无需任何用户交互
  • 我正在调试 HTC One S,Android 4.1 Cyanogen Mod(屏幕 540 x 960)
  • 我没有使用外部库

更新:

Selvin's的帮助下根据我的建议和我个人认为这可能是系统问题,我测试了我的另外两个应用程序。

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

此外,我还发现:

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

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

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

最佳答案

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

关于android - 使用 1 Mb 堆的奇怪位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18515647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com