我无法修复使用canaryLeak检测到的微小内存泄漏。 [视频演示]

时间:2017-03-10 15:32:07

标签: java android memory-leaks leakcanary

我在我的应用中检测到leakCanary的小记忆泄漏,我无法修复。

当我打开NavigationDrawer并打开DialogView一次然后关闭它然后再次打开我的导航器几次时,会检测到泄漏。编辑:打开对话框并解除一次,只是让抽屉打开也会泄漏

See video demo here:

这是泄漏的堆栈跟踪:

enter image description here

NavDrawerFragment.class: 在fragmetns onDetach()中我将引用设置为null但它没有任何帮助

@OnClick(R.id.navDrawer_newList_btn)
public void onNewListBtnClick() {
    addListDialog = new AddShoplistDialog();
    addListDialog.show(getFragmentManager(), AddShoplistDialog.FRAGMENT_TAG);

}


@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    selectionListener = (NavDrawerContract.OnSelectionListener) activity;
}

@Override
public void onDetach() {
    super.onDetach();

    //These dont't solve the leak
    selectionListener = null;
    addListDialog = null;
    recyclerAdapter = null;
}

NavDrawerListAdapter.class 这是RecyclerViewAdapter

RecyclerView的{​​{1}}
NavigationDrawer

NavDrawerListAdapter.Class中的ViewHolder 适配器public NavDrawerListAdapter(@NonNull Context context, @Nullable OrderedRealmCollection<Shoplist> data, NavDrawerContract.OnListItemActions selectionListener) { super(context, data, true); this.realm = Realm.getDefaultInstance(); this.selectionListener = selectionListener; } //Called when NavDrawerFragment's onDestroyView() is called public void onCloseRealm() { realm.close(); selectionListener = null; }

中也使用selectionListener
ViewHolder

1 个答案:

答案 0 :(得分:0)

我只能推测,但我想你是通过NavDrawerListAdapter本身泄漏的,也许是因为你给了Realm一些听众,它引用了你的对话/活动而且你不清楚。