When stepping with the debugger through this, dfString is invalid after [df release]
- (NSString*)dateFormatStringWithLocale:(NSLocale*)locale {
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateStyle:NSDateFormatterShortStyle];
[df setTimeStyle:NSDateFormatterShortStyle];
[df setLocale:locale];
NSString *dfString = [df dateFormat]; // dfString now contains nice date format
[df release]; // seems to also kill dfString ???
return dfString; // dfString is invalid here
}
Let's think about it: dfString is an object, just like any other. I ask for a string from df, with [df dateFormat]. I don't own that string, though, so I don't have to release it. But I own df, so I release it. Now lets assume that string I get from [df dateFormat] is some ivar of df, and gets -release'd in -dealloc of df. Then that damn string is gone. But when I call -retain on that dfString, which is just a pointer to the string owned by df, then damn df won't get released. So, what do I do? copy the string and autorelease it?