I am reading a Big Nerd Ranch book on iOS programming, and I have a question about the Hypnotime program that they create in chapter 7.
At some point, they implement the following method:
- (void)showCurrentTime:(id)sender
{
NSDate *now = [NSDate date];
static NSDateFormatter *formatter = nil;
if (!formatter) {
formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle:NSDateFormatterShortStyle];
}
[timeLabel setText:[formatter stringFromDate:now]];
}
My question is about NSDateFormatter *formatter. Formatting is created using allocand init. I always found out that something with allocshould be released somewhere, right? When formattergoes to timeLabel, doesn't send timeLabelto it retain? And can not (should not?) I subsequently release formatter?
I scanned the code on the next two pages, and I can not find any to issue a message in any place except what releasegoes on timeLabelin dealloc.
? , formatter ? . :)