0

有时,我可以看到报告活动泄漏的 logcat 消息。例如:

Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@4144d6e8 that was originally registered here. Are you missing a call to unregisterReceiver()?

android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@4144d6e8 that was originally registered here. Are you missing a call to unregisterReceiver()?
     at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:763)
     at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:567)
     at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1081)
     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1068)
     at android.app.ContextImpl.registerReceiver(ContextImpl.java:1062)
     at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:341)
     at com.android.internal.content.PackageMonitor.register(PackageMonitor.java:65)
     at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:99)
     at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:53)
     at android.app.Activity.performCreate(Activity.java:4465)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
     at android.app.ActivityThread.access$600(ActivityThread.java:132)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:4575)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
     at dalvik.system.NativeStart.main(Native Method)

我的问题是:如何检测到此活动泄漏?

4

1 回答 1

1

要检测代码中的内存泄漏,您需要为 eclipse 安装Memory Analyzer Tool插件。

要了解如何使用 MAT,请查看以下链接:http ://android-developers.blogspot.in/2011/03/memory-analysis-for-android.html

这是一个非常有用的插件,虽然一开始有点难以理解,但随着您的使用,您将立即检测到内存泄漏。

如果您遇到任何困难,请随时问我。

谢谢 :)

于 2012-07-25T14:36:41.700 回答