InstagramActivity 是第一个 Activity,它将在启动画面后对用户可见。GetDataFromServer 是一个单例,我使用改造用于网络调用。
我无法理解泄漏日志中提到的 mLoadedApk 和 mReceivers。由于我在代码中没有声明引用变量。
D/LeakCanary:
====================================
HEAP ANALYSIS RESULT
====================================
1 APPLICATION LEAKS
References underlined with "~~~" are likely causes.
Learn more at https://squ.re/leaks.
968964 bytes retained by leaking objects
Signature: a29bf580df87c6f6ad305a8d9f7b3bc3a01ea992
┬───
│ GC Root: System class
│
├─ android.provider.FontsContract class
│ Leaking: NO (GetDataFromServer↓ is not leaking and a class is never leaking)
│ ↓ static FontsContract.sContext
├─ instant.saver.for_instagram.api.GetDataFromServer instance
│ Leaking: NO (Application is a singleton)
│ mBase instance of android.app.ContextImpl
│ ↓ Application.mLoadedApk
│ ~~~~~~~~~~
├─ android.app.LoadedApk instance
│ Leaking: UNKNOWN
│ Retaining 1.8 kB in 31 objects
│ mApplication instance of instant.saver.for_instagram.api.GetDataFromServer
│ Receivers
│ ..InstagramActivity@316939088
│ ....InstagramActivity$2@322490448
│ ..GetDataFromServer@316729128
│ ....VisibilityTracker@322489032
│ ↓ LoadedApk.mReceivers
│ ~~~~~~~~~~
├─ android.util.ArrayMap instance
│ Leaking: UNKNOWN
│ Retaining 1.3 kB in 18 objects
│ ↓ ArrayMap.mArray
│ ~~~~~~
├─ java.lang.Object[] array
│ Leaking: UNKNOWN
│ Retaining 1.3 kB in 16 objects
│ ↓ Object[].[0]
│ ~~~
╰→ instant.saver.for_instagram.InstagramActivity instance
Leaking: YES (ObjectWatcher was watching this because instant.saver.for_instagram.InstagramActivity received
Activity#onDestroy() callback and Activity#mDestroyed is true)
Retaining 969.0 kB in 17175 objects
key = 20591e0c-1b12-4810-bc0c-50d74a008298
watchDurationMillis = 14793
retainedDurationMillis = 9769
mApplication instance of instant.saver.for_instagram.api.GetDataFromServer
mBase instance of androidx.appcompat.view.ContextThemeWrapper
====================================
0 LIBRARY LEAKS
A Library Leak is a leak caused by a known bug in 3rd party code that you do not have control over.
See https://square.github.io/leakcanary/fundamentals-how-leakcanary-works/#4-categorizing-leaks
====================================
0 UNREACHABLE OBJECTS
An unreachable object is still in memory but LeakCanary could not find a strong reference path
from GC roots.
====================================
METADATA
Please include this in bug reports and Stack Overflow questions.
Build.VERSION.SDK_INT: 30
Build.MANUFACTURER: OnePlus
LeakCanary version: 2.7
App process name: instant.saver.for_instagram
Stats: LruCache[maxSize=3000,hits=3479,misses=88288,hitRate=3%]
RandomAccess[bytes=4242256,reads=88288,travel=46629354274,range=25009860,size=31821126]
Heap dump reason: 4 retained objects, app is not visible
Analysis duration: 5231 ms
Heap dump file path: /storage/emulated/0/Download/leakcanary-instant.saver.for_instagram/2021-11-10_11-02-28_887.hprof
Heap dump timestamp: 1636522400108
Heap dump duration: 45952 ms
====================================[enter image description here][1]