我读了很多关于位图内存泄漏的信息,但我无法解决我的问题。我有一个应用程序在我的手机上运行良好,但在其他应用程序中我得到 outOfMemoryError 位图大小超过 VM。
我的问题是我不明白如何释放这些资源。我有一个游戏,其中包含多个活动和对话框,在 XML 文件的背景中带有可绘制对象,有时作为布局背景,有时作为全屏的 ImageView。我怎样才能释放这个内存?我不能使用回收,我在销毁活动或关闭对话框时使用 unbindDrawables 方法,但这似乎还不够。
我的垫子概述:
和我的 MAT 内存泄漏嫌疑人: 这是我的支配树:
`Class Name | Shallow Heap | Retained Heap | Percentage
-----------------------------------------------------------------------------------------------------------------------
android.graphics.Bitmap @ 0x42689c38 | 48 | 9.437.248 | 15,43%
class android.content.res.Resources @ 0x40daacb8 System Class | 48 | 5.154.752 | 8,43%
android.graphics.Bitmap @ 0x41674f78 | 48 | 4.194.368 | 6,86%
android.graphics.Bitmap @ 0x41b1f978 | 48 | 4.194.368 | 6,86%
android.graphics.Bitmap @ 0x415954e8 | 48 | 4.096.064 | 6,70%
android.graphics.Bitmap @ 0x416565a8 | 48 | 4.096.064 | 6,70%
android.graphics.Bitmap @ 0x41ab4b70 | 48 | 4.096.064 | 6,70%
android.graphics.Bitmap @ 0x425218a8 | 48 | 4.096.064 | 6,70%
android.graphics.Bitmap @ 0x41664030 | 48 | 2.389.984 | 3,91%
android.graphics.Bitmap @ 0x41ab2b88 | 48 | 2.187.648 | 3,58%
android.graphics.Bitmap @ 0x42687718 | 48 | 1.740.864 | 2,85%
android.graphics.Bitmap @ 0x41ab2818 | 48 | 1.521.024 | 2,49%
android.graphics.Bitmap @ 0x40f796e8 | 48 | 1.127.584 | 1,84%
android.graphics.Bitmap @ 0x41a7f6a0 | 48 | 1.048.640 | 1,71%
android.graphics.Bitmap @ 0x41ab5348 | 48 | 1.048.640 | 1,71%
android.graphics.Bitmap @ 0x42687b08 | 48 | 1.048.640 | 1,71%
android.graphics.Bitmap @ 0x4268dce0 | 48 | 1.048.640 | 1,71%
android.graphics.Bitmap @ 0x426a59c0 | 48 | 1.048.640 | 1,71%
android.graphics.Bitmap @ 0x41bfce38 | 48 | 890.944 | 1,46%
android.graphics.Bitmap @ 0x416796d8 | 48 | 750.784 | 1,23%
android.graphics.Bitmap @ 0x41596ec0 | 48 | 262.208 | 0,43%
android.graphics.Bitmap @ 0x41694318 | 48 | 262.208 | 0,43%
android.graphics.Bitmap @ 0x41a98cb0 | 48 | 262.208 | 0,43%
android.graphics.Bitmap @ 0x41bfefc0 | 48 | 262.208 | 0,43%
android.graphics.Bitmap @ 0x42790e90 | 48 | 262.208 | 0,43%
class android.text.Html$HtmlParser @ 0x40e7ade0 System Class | 8 | 126.632 | 0,21%
class java.lang.ref.FinalizerReference @ 0x40d0fef0 System Class | 16 | 118.464 | 0,19%
class libcore.icu.TimeZones @ 0x40d152b0 System Class | 40 | 103.432 | 0,17%
android.graphics.Bitmap @ 0x40f450a0 | 48 | 100.288 | 0,16%
com.android.org.bouncycastle.jce.provider.BouncyCastleProvider @ 0x40e0e0d8| 112 | 80.096 | 0,13%
android.graphics.Bitmap @ 0x426a4718 | 48 | 66.624 | 0,11%
android.graphics.Bitmap @ 0x4158c1a0 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41592a58 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41655380 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41a90980 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41aa9718 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41ab4178 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41ab43b0 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41ab8440 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41adc988 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x41b0ae10 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x422e46c0 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x42520580 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x42684680 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x42686db8 | 48 | 65.600 | 0,11%
android.graphics.Bitmap @ 0x4268ab38 | 48 | 65.600 | 0,11%
android.graphics.drawable.StateListDrawable$StateListState @ 0x426a5800 | 80 | 63.064 | 0,10%
android.graphics.drawable.StateListDrawable$StateListState @ 0x426f3458 | 80 | 63.064 | 0,10%
android.graphics.drawable.NinePatchDrawable @ 0x426f2bc0 | 72 | 62.464 | 0,10%
android.graphics.drawable.NinePatchDrawable @ 0x427404e8 | 72 | 62.464 | 0,10%
android.graphics.NinePatch @ 0x426b5030 | 32 | 62.288 | 0,10%
Total: 51 of 15.374 entries | | |
-----------------------------------------------------------------------------------------------------------------------
`
我从MAT开始,我的记忆力太差了吗?如果不使用位图,如何正确释放背景内存?
谢谢。