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.
网友评论