Leakcanary report of memory leak using Otto

前端 未结 1 1075
-上瘾入骨i
-上瘾入骨i 2021-01-06 06:58

Following up on my last question, here is the second memory leak I can not get rid of..

I read that I need to register and unregister my static Otto bus according to

相关标签:
1条回答
  • 2021-01-06 07:14

    You are using watching the reference at the wrong time. You should only call watch(thing) when you are absolutely certain that thing will be garbage collected. For your Activities and Fragments, you will want something like this:

    @Override public void onDestroy() {
        super.onDestroy();
        RefWatcher refWatcher = ExampleApplication.getRefWatcher(getActivity());
        refWatcher.watch(this);
    }
    

    That is from the LeakCanary FAQ "How do I use it?" section

    0 讨论(0)
提交回复
热议问题