LeakCanary 没有提供足够的信息来识别泄漏

Shi*_*yal 3 android memory-leaks memory-profiling android-activity java-memory-leaks

我正在使用 LeakCanary,但堆分析结果没有提供足够的信息来检测任何泄漏。它只提到活动正在泄漏。

\n
D/LeakCanary: \xe2\x80\x8b\n    ====================================\n    HEAP ANALYSIS RESULT\n    ====================================\n    1 APPLICATION LEAKS\n    \n    References underlined with "~~~" are likely causes.\n    Learn more at https://squ.re/leaks.\n    \n    298153 bytes retained by leaking objects\n    Signature: a610bac3ef989ac5dc5a69244fc2882de5617\n    \xe2\x94\xac\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n    \xe2\x94\x82 GC Root: System class\n    \xe2\x94\x82\n    \xe2\x94\x9c\xe2\x94\x80 android.provider.FontsContract class\n    \xe2\x94\x82    Leaking: NO (MyApplication\xe2\x86\x93 is not leaking and a class is never leaking)\n    \xe2\x94\x82    \xe2\x86\x93 static FontsContract.sContext\n    \xe2\x94\x9c\xe2\x94\x80 com.example.MyApplication instance\n    \xe2\x94\x82    Leaking: NO (Application is a singleton)\n    \xe2\x94\x82    mBoundService instance of com.example.services.SessionService\n    \xe2\x94\x82    mBase instance of android.app.ContextImpl\n    \xe2\x94\x82    \xe2\x86\x93 Application.mLoadedApk\n    \xe2\x94\x82                  ~~~~~~~~~~\n    \xe2\x94\x9c\xe2\x94\x80 android.app.LoadedApk instance\n    \xe2\x94\x82    Leaking: UNKNOWN\n    \xe2\x94\x82    Retaining 302.8 kB in 4641 objects\n    \xe2\x94\x82    mApplication instance of com.example.MyApplication\n    \xe2\x94\x82    \xe2\x86\x93 LoadedApk.mReceivers\n    \xe2\x94\x82                ~~~~~~~~~~\n    \xe2\x94\x9c\xe2\x94\x80 android.util.ArrayMap instance\n    \xe2\x94\x82    Leaking: UNKNOWN\n    \xe2\x94\x82    Retaining 301.7 kB in 4615 objects\n    \xe2\x94\x82    \xe2\x86\x93 ArrayMap.mArray\n    \xe2\x94\x82               ~~~~~~\n    \xe2\x94\x9c\xe2\x94\x80 java.lang.Object[] array\n    \xe2\x94\x82    Leaking: UNKNOWN\n    \xe2\x94\x82    Retaining 301.7 kB in 4613 objects\n    \xe2\x94\x82    \xe2\x86\x93 Object[].[2]\n    \xe2\x94\x82               ~~~\n    \xe2\x95\xb0\xe2\x86\x92 com.example.activities.SelectActivity instance\n    \xe2\x80\x8b     Leaking: YES (ObjectWatcher was watching this because com.example.activities.SelectActivity received\n    \xe2\x80\x8b     Activity#onDestroy() callback and Activity#mDestroyed is true)\n    \xe2\x80\x8b     Retaining 298.2 kB in 4579 objects\n    \xe2\x80\x8b     key = 68660c30-bc17-4a74-a5e2-c54f6d676c59\n    \xe2\x80\x8b     watchDurationMillis = 5185\n    \xe2\x80\x8b     retainedDurationMillis = 183\n    \xe2\x80\x8b     mApplication instance of com.example.MyApplication\n    \xe2\x80\x8b     mBase instance of androidx.appcompat.view.ContextThemeWrapper\n    ====================================\n    0 LIBRARY LEAKS\n\n
Run Code Online (Sandbox Code Playgroud)\n

我从这个痕迹中所知道的就是SelectActivity泄漏。但我不明白为什么?该活动本身有 1000 多行,我希望除了检查每一行并检查可能的泄漏候选者之外是否还有其他捷径。

\n

Pie*_*cau 5

该活动是否注册任何广播接收器?泄漏跟踪显示 LoadedApk.mReceivers 它是接收器到接收器调度程序的 ArrayMap,而活动是接收器调度程序。