LeakCanary 没有提供足够的信息来识别泄漏
LeakCanary not giving enough information to identify leak
我正在使用 LeakCanary,但堆分析结果没有提供足够的信息来检测任何泄漏。它只提到 activity 正在泄漏。
D/LeakCanary:
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
298153 bytes retained by leaking objects
Signature: a610bac3ef989ac5dc5a69244fc2882de5617
┬───
│ GC Root: System class
│
├─ android.provider.FontsContract class
│ Leaking: NO (MyApplication↓ is not leaking and a class is never leaking)
│ ↓ static FontsContract.sContext
├─ com.example.MyApplication instance
│ Leaking: NO (Application is a singleton)
│ mBoundService instance of com.example.services.SessionService
│ mBase instance of android.app.ContextImpl
│ ↓ Application.mLoadedApk
│ ~~~~~~~~~~
├─ android.app.LoadedApk instance
│ Leaking: UNKNOWN
│ Retaining 302.8 kB in 4641 objects
│ mApplication instance of com.example.MyApplication
│ ↓ LoadedApk.mReceivers
│ ~~~~~~~~~~
├─ android.util.ArrayMap instance
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4615 objects
│ ↓ ArrayMap.mArray
│ ~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4613 objects
│ ↓ Object[].[2]
│ ~~~
╰→ com.example.activities.SelectActivity instance
Leaking: YES (ObjectWatcher was watching this because com.example.activities.SelectActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 298.2 kB in 4579 objects
key = 68660c30-bc17-4a74-a5e2-c54f6d676c59
watchDurationMillis = 5185
retainedDurationMillis = 183
mApplication instance of com.example.MyApplication
mBase instance of androidx.appcompat.view.ContextThemeWrapper
====================================
0 LIBRARY LEAKS
我从这个跟踪中知道的是 SelectActivity
正在泄漏。但我想不通为什么? activity 本身有 1000 多行,我希望除了遍历每一行并检查可能的泄漏候选之外是否有任何捷径。
activity是否注册了任何广播接收器?泄漏跟踪显示 LoadedApk.mReceivers 是接收器到接收器调度器的 ArrayMap,activity 是接收器调度器。
我正在使用 LeakCanary,但堆分析结果没有提供足够的信息来检测任何泄漏。它只提到 activity 正在泄漏。
D/LeakCanary:
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
298153 bytes retained by leaking objects
Signature: a610bac3ef989ac5dc5a69244fc2882de5617
┬───
│ GC Root: System class
│
├─ android.provider.FontsContract class
│ Leaking: NO (MyApplication↓ is not leaking and a class is never leaking)
│ ↓ static FontsContract.sContext
├─ com.example.MyApplication instance
│ Leaking: NO (Application is a singleton)
│ mBoundService instance of com.example.services.SessionService
│ mBase instance of android.app.ContextImpl
│ ↓ Application.mLoadedApk
│ ~~~~~~~~~~
├─ android.app.LoadedApk instance
│ Leaking: UNKNOWN
│ Retaining 302.8 kB in 4641 objects
│ mApplication instance of com.example.MyApplication
│ ↓ LoadedApk.mReceivers
│ ~~~~~~~~~~
├─ android.util.ArrayMap instance
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4615 objects
│ ↓ ArrayMap.mArray
│ ~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ Retaining 301.7 kB in 4613 objects
│ ↓ Object[].[2]
│ ~~~
╰→ com.example.activities.SelectActivity instance
Leaking: YES (ObjectWatcher was watching this because com.example.activities.SelectActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 298.2 kB in 4579 objects
key = 68660c30-bc17-4a74-a5e2-c54f6d676c59
watchDurationMillis = 5185
retainedDurationMillis = 183
mApplication instance of com.example.MyApplication
mBase instance of androidx.appcompat.view.ContextThemeWrapper
====================================
0 LIBRARY LEAKS
我从这个跟踪中知道的是 SelectActivity
正在泄漏。但我想不通为什么? activity 本身有 1000 多行,我希望除了遍历每一行并检查可能的泄漏候选之外是否有任何捷径。
activity是否注册了任何广播接收器?泄漏跟踪显示 LoadedApk.mReceivers 是接收器到接收器调度器的 ArrayMap,activity 是接收器调度器。