Here I got some ugly code:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
NSDate *date = [NSDate date];
NSString *textWithYear = [NSString stringWithFormat:@"text and year %@", [dateFormatter stringFromDate:date] ];
[dateFormatter release];
NSLog(@"%i", [dateFormatter retainCount]); // returns 1 !
As you see, retains counter returns 1, which I suppose means that the object is not released. If I change that string to
[dateFormatter release], dateFromatter = nil;
retains counter returns 0, which is supposedly because it can't count retains for nil :)
Is there something that I don't understand about retains counter, or this object is really not released? When I send release
to it for the second time (striving to get zero retains count) it crushes expectedly :)
And one more question: if the dateFormatter was really released, why doesn't it crash when i call [dateFormatter retainCount] ?