With all of these callbacks, there is a danger that objects waiting for the callbacks might not get deallocated correctly. Thus, it was decided that:
Notification centers do not own their observers. If an object is an observer, it will typically remove itself from the notification center in its dealloc method:
- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }
Objects do not own their delegates or data sources. If you create an object that is a delegate or data source, your object should “excuse” itself in its dealloc method:
- (void)dealloc { [windowThatBossesMeAround setDelegate:nil]; [tableViewThatBegsForData setDataSource:nil]; }
Objects do not own their targets. If you create an object that is a target, your object should zero the target pointer in its dealloc method:
- (void)dealloc { [buttonThatKeepsSendingMeMessages setTarget:nil]; }
None of these issues exist in this program because your Logger object will not be deallocated before the program terminates. (Also, in a bit of a fluke, in this exercise I used two well-documented exceptions to the rules: an NSURLConnection owns its delegate and an NSTimer owns its target.)