自动释放池困境

时间:2012-07-26 15:24:51

标签: iphone objective-c ios ipad

所以我对自动发布池有疑问。我创建了一个使用它如下:

dispatch_async(dispatch_get_main_queue(), ^{
            NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
            NSMutableAttributedString * attributedString = [NSMutableAttributedString attributedStringWithString:object.text];
            [attributedString setFont:[UIFont fontWithName:@"HelveticaNeue" size:15]];
            [self.titleLabel_ setAttributedString:attributedString];
            [self.titleLabel_ setLinkColor:self.textColor_];
            [self parseTagsInComment];
            [pool release];
        });

这是否是自动释放池的错误用法,因为我已经有一个自动释放的对象?

1 个答案:

答案 0 :(得分:0)

是的,这是对的。在autoreleased之后,pool中的所有release个对象都会收到[pool release];条消息 因此,如果保留计数变为0,则会从内存中刷新NSMutableAttributedStringUIFont将被释放。