我在我的应用中检测到leakCanary
的小记忆泄漏,我无法修复。
当我打开NavigationDrawer
并打开DialogView
一次然后关闭它然后再次打开我的导航器几次时,会检测到泄漏。编辑:打开对话框并解除一次,只是让抽屉打开也会泄漏
这是泄漏的堆栈跟踪:
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
答案 0 :(得分:0)
我只能推测,但我想你是通过NavDrawerListAdapter
本身泄漏的,也许是因为你给了Realm一些听众,它引用了你的对话/活动而且你不清楚。