开发者

When does retain count for an autoreleased object decrement?

If I have an autoreleased object, when does its retain count (i.e. the value returned when I call the method retainCount on it) decrement? I had figured it to be when the scope of the method the object was allocated within ended, but my tests aren't indicating that. I have code like the following:

int itemIndex = 0;
NSArray* items = [mResponse componentsSeparatedByString:@","];  
self.mText 开发者_运维问答= (NSString*)[items objectAtIndex:itemIndex++];
self.mText = [mText gtm_stringByUnescapingFromURLArgument];
NSLog(@"retain count: %d",[mText retainCount]);

This returns 2 for the count (mText has a retain property so that makes sense), and after exiting this method, the call from outside likewise returns 2.


Don't look at retainCount. It's misleading. As long as you follow the Memory Management Programming Guide then you'll be fine.

If you rephrase your question to say "When does the default autorelease pool drain?" then the answer is when control flow returns to the runloop.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜