Edit: I’m really sorry. I edited the confusing errors I made in my post.
I have these ivars declared in WhereamiViewController.h:
CLLocationManager *locationManager;
IBOutlet MKMapView *worldView;
IBOutlet UITextField *locationTitleField;
The author writes that since WhereamiViewController owns locationManager and locationManager's delegate is the WhereamiViewController, locationManager delegate must be set to nil in the WhereamiViewController's dealloc method because the delegate is assigned instead of weak. In the .xib file worldView and locationTitleField are set to delegate the File's Owner, but why don’t those two delegates need to be set to nil when both of them are also assign instead of weak?
PS: It’s using ARC
Well you need to set it to
nilsimply as a precautionary measure. Did I Confuse you? Let me explain.The setting to
nilhas really nothing to do withretainreleasecycle, it is simply to avoidlocationManagersending delegate call to your controller. For instance, iflocationManageris updating location meanwhile your controller is released, thelocationManagerstill having thedelegatereference set to your view controller, will call the delegate with location parameters.But since you controller has been deallocated, the call will result in bad memory access.
However, if you set it to
nil, exception will not be thrown since manipulatin ofnilpointers has no affect.