所以我对自动发布池有疑问。我创建了一个使用它如下:
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];
});
这是否是自动释放池的错误用法,因为我已经有一个自动释放的对象?
答案 0 :(得分:0)
是的,这是对的。在autoreleased
之后,pool
中的所有release
个对象都会收到[pool release];
条消息
因此,如果保留计数变为0
,则会从内存中刷新NSMutableAttributedString
并UIFont
将被释放。