问题描述
我有一个内存泄漏,这是我在日志行第一次看到的:资源无法调用release。
我安装了LeakCanary以查看是否可以找到它,并告诉我它是
├─ android.widget.FrameLayout instance
D/LeakCanary: │ Leaking: NO (View attached)
D/LeakCanary: │ View is part of a window view hierarchy
D/LeakCanary: │ View.mAttachInfo is not null (view attached)
D/LeakCanary: │ View.mID = R.id.nav_host_fragment
D/LeakCanary: │ View.mWindowAttachCount = 1
D/LeakCanary: │ mContext instance of com.salinas.builder.MainActivity with mDestroyed = false
D/LeakCanary: │ ↓ FrameLayout.mCurrentDragChild
D/LeakCanary: │ ~~~~~~~~~~~~~~~~~
D/LeakCanary: ╰→ androidx.constraintlayout.widget.ConstraintLayout instance
我不确定我是否正确理解了这一点,似乎mCurrentDragChild在某种程度上是原因,而我没有办法实现这一点。我查看了源代码,看不到如何做才能将此值设置为任何值。它在ViewGroup中作为View实例变量,并且没有对onDestroyView的调用。
似乎没有其他人遇到这个问题,所以我认为我做错了其他事情。
我的Drag侦听器是:
v.setonDragListener(new View.OnDragListener(){
@Override
public boolean onDrag(View v,DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
v.setBackground(enterShape);
break;
case DragEvent.ACTION_DRAG_EXITED:
v.setBackground(normalShape);
break;
case DragEvent.ACTION_DROP:
v.setBackground(normalShape);
View view = (View) event.getLocalState();
if (view instanceof NeighborLayout) {
dropNeighbor(view);
} else if (view instanceof RegionLayout){
dropFamily(view);
}
break;
case DragEvent.ACTION_DRAG_ENDED:
if (! event.getResult()){
View w = (View) event.getLocalState();
w.setVisibility(View.VISIBLE);
}
break;
default:
break;
}
return true;
}
});
编辑 我做了一些进一步的工作,试图了解正在发生的事情。 如果我没有将拖放操作放到放置目标中,则结果与我放置时的结果相同,但仍显示失败释放消息。 LeakCanary告诉我我有泄漏。
如果我执行了拖放操作,则不会显示该消息,并且LeakCanary处于安静状态。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)