0

我写了一个 android 应用程序,并试图避免内存泄漏。为此,我使用了 Eclipse 内存分析器。我有三个问题嫌疑人。每个都是关于大尺寸的位图对象(两个是 8.8MB,一个是 5.8 MB)。我在我的代码中做了一些技巧,我不确定它们是否导致了这个:

  • 我将活动设置为某些视图的 OnClickListener。
  • 我在运行时自定义视图中创建,使用 getApplicationContext() 作为上下文。
  • 我在活动类中声明了用于保存视图的字段。

其中之一是否可能导致内存泄漏?或者可能有 8.8MB 位图是正常的?

在详细介绍时,我看到例如第一个位图由以下内容保存:

byte[9216000] @ 0x42dda5b0 ..&...$...#...%...(...*...$... .........................z...t...t...y.........#...+...,...-...........(... .......$...*...&...%...%...&...'...'...#...........!...%...'...!... ..."...'...)...(...!.......!...*...-...,...+...'...$...&...&...$...........!...&....
 9,216,016 9,216,016 
\mBuffer android.graphics.Bitmap @ 0x418f9028
.+mBitmap android.graphics.drawable.BitmapDrawable @ 0x420211b8
.|\mBGDrawable android.widget.LinearLayout @ 0x41fb5528
.|.\[0] android.view.View[12] @ 0x41fcbf60
.|..\mChildren android.widget.FrameLayout @ 0x41fb4c90 
.|...\mContentParent com.android.internal.policy.impl.PhoneWindow @ 0x4220f480
.|....+this$0 com.android.internal.policy.impl.PhoneWindow$DecorView @ 0x41fd8bd0
.|....|+mView android.view.ViewRootImpl @ 0x4220f5c0
.|....||+this$0 android.view.ViewRootImpl$2 @ 0x42032ed8 Native Stack
.|....||+this$0 android.view.ViewRootImpl$AccessibilityInteractionConnectionManager @ 0x420330f0 »
.|....||\Total: 2 entries
.|....|+[1] android.view.View[5] @ 0x41932f18 »
4

0 回答 0