首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >LeakCanary收到Fragment#onDestroy()回调,但Fragment#mFragmentManager为空

LeakCanary收到Fragment#onDestroy()回调,但Fragment#mFragmentManager为空
EN

Stack Overflow用户
提问于 2020-08-05 15:16:35
回答 1查看 4.9K关注 0票数 8

我正在尝试使用LeakCanary修复内存泄漏,但老实说,我无法理解向我显示的堆栈跟踪。我使用了一个firebase分页选项,并停止了对onDestroy方法的侦听。我也没有向适配器传递任何活动或上下文,所以我确信这不会有任何问题。以下是来自LeakCanary的日志。

代码语言:javascript
运行
复制
    HEAP ANALYSIS RESULT
    ====================================
    1 APPLICATION LEAKS
    
    References underlined with "~~~" are likely causes.
    Learn more at https://squ.re/leaks.
    
    31417285 bytes retained by leaking objects
    Signature: 31c372d2f2d3d219e828763d8f853ceca5851b
    ┬───
    │ GC Root: System class
    │
    ├─ leakcanary.internal.InternalLeakCanary class
    │    Leaking: NO (HomeBuyersActivity↓ is not leaking and a class is never leaking)
    │    ↓ static InternalLeakCanary.resumedActivity
    ├─ com.dreamakers.coonna.Activity.HomeBuyersActivity instance
    │    Leaking: NO (Activity#mDestroyed is false)
    │    ↓ HomeBuyersActivity.mLifecycleRegistry
    │                         ~~~~~~~~~~~~~~~~~~
    ├─ androidx.lifecycle.LifecycleRegistry instance
    │    Leaking: UNKNOWN
    │    ↓ LifecycleRegistry.mObserverMap
    │                        ~~~~~~~~~~~~
    ├─ androidx.arch.core.internal.FastSafeIterableMap instance
    │    Leaking: UNKNOWN
    │    ↓ FastSafeIterableMap.mEnd
    │                          ~~~~
    ├─ androidx.arch.core.internal.SafeIterableMap$Entry instance
    │    Leaking: UNKNOWN
    │    ↓ SafeIterableMap$Entry.mKey
    │                            ~~~~
    ├─ com.dreamakers.coonna.Adapter.DiscoverStoreAdapter instance
    │    Leaking: UNKNOWN
    │    ↓ DiscoverStoreAdapter.mParser
    │                           ~~~~~~~
    ├─ com.dreamakers.coonna.Activity.HomeFragment$11 instance
    │    Leaking: UNKNOWN
    │    Anonymous class implementing com.firebase.ui.firestore.SnapshotParser
    │    ↓ HomeFragment$11.this$0
    │                      ~~~~~~
    ╰→ com.dreamakers.coonna.Activity.HomeFragment instance
    ​     Leaking: YES (ObjectWatcher was watching this because com.dreamakers.coonna.Activity.HomeFragment received Fragment#onDestroy() callback and Fragment#mFragmentManager is null)
    ​     key = 6e0451ae-0c0b-4de8-8993-011515e95a80
    ​     watchDurationMillis = 6238
    ​     retainedDurationMillis = 1238
    ====================================
    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
    ====================================
    METADATA
EN

Stack Overflow用户

回答已采纳

发布于 2020-08-07 00:24:00

HomeFragment已被销毁,应进行垃圾回收,但无法对其进行垃圾回收,因为DiscoverStoreAdapter已注册为HomeBuyersActivity上的生命周期侦听器,并且DiscoverStoreAdapter具有mParser字段,该字段是在HomeFragment中实现SnapshotParser的匿名类。

没有代码就很难说,但是当片段被销毁时,DiscoverStoreAdapter.mParser可能应该设置为null。

票数 3
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63260185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档