Possible Duplicate:
In dealloc method set any delegate to nil is needed or not needed
In ARC if class Foo owns an ivar and that ivar’s delegate is set to Foo is it always a good safety precaution to set the ivar’s delegate to nil in dealloc or is this precaution only used in some cases?
It depends on the ivar. If
Fooowns it “exclusively” and the ivar is not available to other classes, then there is no need to do_ivar.delegate = nil;indealloc. But if the object is intended to be used in other classes as well, you would better to set the delegate to nil. However, this is very rare situation in Cocoa development.Another approach mentioned in the answers is to always be safe and set the
delegatetonil. But I would not recommend this. Sometimes, by leaving the delegate reference you may find a leaked object which tries to contact its “dead” delegate which owned it.