繁体   English   中英

如何消除仪器中发现的泄漏

[英]how do you remove leaks discovered in Instruments

我只是在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];
                }];
            });

        });

如果您在最新的主服务器上使用Nimbus,则必须启用ARC,否则会发生内存泄漏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM