2018-12-21

iOS开发中懒加载遇到的坑

正常写一个懒加载对象

- (MAMapView*)mapView{

    if(nil==_mapView) {

        _mapView= [[MAMapViewalloc]init];

        _mapView.delegate = self;

    }

    return _mapView;

}

由于定位服务没开启,没用到mapView对象就返回页面,这是页面销毁调用下面方法会崩溃

- (void)dealloc {

    self.mapView = nil;

}

Cannot form weak reference to instance (0x7fbff4f6c6c0) of class MFChatRoomBoardController. It is possible that this object was over-released, or is in the process of deallocation.

dealloc中self.mapView = nil ,调用了懒加载中  _mapView.delegate = self; 造成了奔溃。

 说明不允许在 dealloc 的时候 对weak修饰的对象赋值self.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容