简体   繁体   中英

Why set delegate nil when the instance is dealloced?

I use faux pas to check my code, and it says

When an object sets itself as the delegate or data source of one of its members, it must detach that reference in its -[NSObject dealloc] method.

So I need to write

- (void)dealloc
{
    self.tipsView.delegate = nil;
}

Why? If the delegate is weak, I cannot find the necessity to set it nil when it deallocs.

The only reason to do that is if you are not using ARC. I think the tool is either old or not configured to know that you are using ARC.

In case your delegate is weak reference you are right, setting it to nil makes no sense. The tool is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM