Reputation: 1
I've struck a problem using the latest XCode beta (4.2 Build 4C114, iOS 5.0) and autorelease that I can't solve. The code needs to conditionally set a string which will be the message in an alert:
NSString* msg = ([result rangeOfString:@"Ok"].location == NSNotFound) ?
@"Upload failed" : @"Uploaded ok";
Running Analyze highlights the line saying "Object sent -autorelease too many times (2)". And sho'nuf, running the app (under the Simulator) causes a SIGABRT double free.
I've tried coding the line as an if/else.
I've tried creating separate strings for the two messages and just assigning the appropriate pointer to a third pointer with the ternary and if/else.
Nothing I do makes this go away!
Upvotes: 0
Views: 1003
Reputation: 2201
Creating a string with @"string contents" will always be autoreleased automatically. You don't need to specifically release it yourself.
In most cases you would only need to release an object if you called "alloc" or "new" on it to begin with.
Upvotes: 1