Как убрать утечки, обнаруженные в приборах
Я просто запустил инструмент "Утечки" в "Инструментах" и обнаружил следующие утечки:
в основном он указывает на drawRect в NIAttributedLabel, поэтому я дважды щелкнул метод 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];
}];
});
});
1 ответ
Решение
Если вы используете Nimbus на последнем мастере, вы должны включить ARC, иначе вы получите утечки памяти.