Is there a memory leak here?
Posted
by TheLearner
on Stack Overflow
See other posts from Stack Overflow
or by TheLearner
Published on 2010-05-31T17:38:12Z
Indexed on
2010/05/31
17:43 UTC
Read the original article
Hit count: 253
objective-c
|memory-leaks
Please see my comments in code:
-(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t { [super init]; coordinate = c; NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
NSString* formattedDate = [NSString stringWithFormat:@"%@ %@",
[dateFormatter stringFromDate:today], t];
[self setTitle:formattedDate]; //Why does the app crash when I try and release formattedDate? I have after all passed its reference to the title property?
[dateFormatter release]; //I need to release the dateformatter because I have finished using it and I have not passed on a reference to it
return self;
}
© Stack Overflow or respective owner