问题
I am using DataBindingUtil
to bind views to variables:
public class MyView extends ConstraintLayout {
private ViewMyViewBinding views;
public MyView(Context context) {
super(context);
init(context);
}
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
views = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.myview, this, true);
}
}
Do I have to call views.unbind();
to avoid a memory leak when the view is detached/destroyed, and if yes, when is it best to call this?
Update
I tested with LeakCanary and it doesn't report any leaks without unbinding.
来源:https://stackoverflow.com/questions/59231333/is-unbinding-necessary-when-using-databindingutil