我刚刚在 Instruments 中运行了 Leaks 工具,发现了以下漏洞:
基本上它指出了 NIAttributedLabel 中的 drawRect,所以我双击了 drawRect 方法,这就是我所拥有的:
我该如何消除这种泄漏?
这是一些代码:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSString *commentsText = [NSString stringWithFormat:@"%@ %@", self.imageComment_.username_, self.imageComment_.text_];
NSRange range;
range.location = 0;
range.length = commentsText.length;
NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc] initWithString:commentsText];
[attrStr setFont:[UIFont fontWithName:@"HelveticaNeue" size:14] range:range];
self.commentAttributedString_ = attrStr;
[attrStr release];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.commentsText_ setAlpha:0.0];
[weakSelf.commentsPostedTime_ setAlpha:0.0];
[weakSelf.commentsText_ setFrameWidth:weakSelf.contentView.frameWidth - weakSelf.profilePicture_.frameWidth - kCommentsPadding];
[weakSelf.commentsText_ setFrameHeight:weakSelf.imageComment_.commentHeight_ - 30];
[weakSelf.commentsText_ setAttributedString:weakSelf.commentAttributedString_];
[weakSelf.commentsText_ setLinkColor:weakSelf.textColor_];
NSString *timePosted = [NSString timestampToString:weakSelf.imageComment_.createdTime_];
CGSize commentsTimeSize = [timePosted sizeWithFont:weakSelf.commentsPostedTime_.font constrainedToSize:CGSizeMake(weakSelf.commentsText_.frameWidth, 50)];
[weakSelf.commentsPostedTime_ setText:timePosted];
[weakSelf.commentsPostedTime_ setFrameWidth:commentsTimeSize.width];
[weakSelf.commentsPostedTime_ setFrameHeight:commentsTimeSize.height];
[weakSelf.commentsPostedTime_ setFrameY:weakSelf.commentsText_.frameY + weakSelf.commentsText_.frameHeight];
[weakSelf.commentsPostedTime_ setFrameX:weakSelf.commentsText_.frameX];
[UIView animateWithDuration:0.3 animations:^{
[weakSelf.commentsText_ setAlpha:1.0];
[weakSelf.commentsPostedTime_ setAlpha:1.0];
} completion:^(BOOL finished){
[weakSelf parseTagsInComment];
}];
});
});