Is unbinding necessary when using DataBindingUtil?

China☆狼群 提交于 2020-01-25 08:14:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!