Object sent -autorelease too many times

Posted by mongeta on Stack Overflow See other posts from Stack Overflow or by mongeta
Published on 2010-05-13T07:04:06Z Indexed on 2010/05/13 7:14 UTC
Read the original article Hit count: 310

Filed under:
|
|

I have this code that simple returns Today's date as a string formatted:

+(NSString*) getTodayString_YYYY_MM_DD {

  NSDate    * today = [NSDate date];

  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"yyyy-MM-dd"]; 

  return [[formatter stringFromDate:today] autorelease];

}

With instruments I'm not getting a memory leak, but when I Analyze, XCode says:

Object sent -autorelease too many times

If I understand correctly, I have to release manually the formatter as I'm creating it using 'alloc', but I can't release here because I have to return the value, so I add the autorelease.

How I can do it better to improve it ?

thanks,

r.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c