Leak canary, Recyclerview leaking mAdapter

前端 未结 4 1231
我寻月下人不归
我寻月下人不归 2021-01-30 16:33

I decided it was high time I learned how to use Leak Canary to detect Leaks within my apps, and as I always do, I tried to implement it in my project to really understand how to

4条回答
  •  时光说笑
    2021-01-30 17:27

    I can't open your image and see the actual leak but if you define a local variable for your RecyclerView in your Fragment and set your fragment's retainInstanceState true it can cause possible leaks with rotation.

    When using a Fragment with retainInstance you should clear all your ui references in onDestroyView

    @Override
    public void onDestroyView() {
         yourRecyclerView = null;
         super.onDestroyView();
    }
    

    Here you can find a detailed information from this link: Retained Fragments with UI and memory leaks

提交回复
热议问题