Why do we set delegate to nil at dealloc if the object is going to be destroyed anyway?

后端 未结 4 1107
死守一世寂寞
死守一世寂寞 2021-02-15 17:18
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
    PO(NSStringFromCGPoint(self.tableView.contentOffset));
    PO(NSStringFromUIEdgeInsets(self.tableView.conten         


        
4条回答
  •  心在旅途
    2021-02-15 17:23

    You need to set delegate to nil in many cases. In your case tableView can be referenced by some external class and will not destroyed after your class dealloc method. And will continue call its delegate method leading to crash. There are several classes that works in another thread (NSURLConnection for example). Even if you release it it can continue calls delegate methods since it is retained in another thread.

提交回复
热议问题