开发者

Object sent -autorelease too many times (iOS5)

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 开发者_Python百科and just assigning the appropriate pointer to a third pointer with the ternary and if/else. Nothing I do makes this go away!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜