Search code examples
iosdelegatesdealloc

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.


Solution

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