采用1 MB的堆怪位图位图、MB

2023-09-03 21:48:56 作者:相贱不如怀念

出于好奇,我刚刚测试了我的Andr​​oid应用程序的内存泄漏,使用 Eclipse的内存分析器。

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

我碰到一个奇怪的位图中的 512×512像素的大小最多约1兆字节我的设备堆内存。

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

我检查了我可绘制文件夹,再也找不到该大小的位图(512×512)。

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

我开始使用Google和碰到这个问题,其中用户介绍了如何获得实际的图像背后的内存分析器一个内存泄漏参考:

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的内存分析器) - 如何看待从内存转储位图

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

我也跟着教程,并用GIMP的帮助下,我摘录如下图:

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

所以,我的问题是:

那是什么? 什么是它在我的应用程序堆在干什么? 如何摆脱它? 在没有任何人有相同的位图在他的堆?

注:

在我可绘制文件夹没有位图看像 在我的应用程序使用的最大的位图是140×140像素 在我有一种感觉,这个位图某种程度上来自系统 在该位图是在堆的应用程序启动后右 - 无需任何用户交互 在我调试上的HTC One S,安卓4.1氰MOD(屏幕540 * 960) 在我没有使用外部库

更新

使用 Selvin的暗示的帮助,我个人的感觉,这可能是一个系统的问题,我测试了两种其他我的应用程序。

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.

无论我所测试的应用程序也显示了同样的位图,在内存分析器完全相同的量占用的字节:

此外,我能找到的是:

位图的源总是与应用程序的发射活动有关。

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

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.

推荐答案

使用Android的默认窗口背景是一个512x512的图像(你与黑暗的主题或灰白色渐变的灯光主题见青色,暗渐变)。在功能的设备,这一形象被替换为程序性梯度的Andr​​oid 4.2。

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.

下面是两个512x512的背景我说的是如果你有兴趣:

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

https://m.xsw88.com/allimgs/daicuo/20230903/5686.png

https://m.xsw88.com/allimgs/daicuo/20230903/5687.png

 
精彩推荐