Mvp避免内存泄漏

在p层

    public void attachView(T t){

        tWeakReference = new WeakReference<>(t);
    }

    public void detachView(){

        if (tWeakReference.get()!=null){
            tWeakReference.clear();
            tWeakReference=null;

        }

    }


Activity里
   showPresenter = new ShowPresenter(this);
        showPresenter.attachView(this);
        showPresenter.send();

 @Override
    protected void onDestroy() {
        super.onDestroy();
        showPresenter.detachView();
        Log.i("rrr","销毁了");
    }

猜你喜欢

转载自blog.csdn.net/weixin_43814403/article/details/87644848