解决泄漏

在P层自定义两个方法

 //与P层关联 处理内存泄露
public  void  attachview (T view){
    mviewModel =new WeakReference<T>(view);
}
更改类名泛型
public class Showpresenter<T> {
    private Reference<T> mviewModel;

// P层解除关联
 public  void  detachview(){
       if (mviewModel.get()!=null){
           mviewModel.clear();
           mviewModel=null;
       }
  }

activity 调用

 //关联  解决内存泄漏
showpresenter.attachview(this);

在销毁的生命周期中调用销毁方法
//解决MVP造成的内存泄露
@Override
protected void onDestroy() {
    super.onDestroy();
       //activity 销毁之前P层先进行毁掉
    showpresenter.detachview();
             Log.i("oo","销毁掉了");
}

猜你喜欢

转载自blog.csdn.net/weixin_43882910/article/details/87542537