how do you remove leaks discovered in Instruments

126 Views Asked by At

I just ran the Leaks tool in Instruments and discovered the following leaks:

enter image description here

basically it's pointing out to drawRect in NIAttributedLabel, so I double clicked the drawRect method and here's what I have:

How do I then eliminate this leak? enter image description here

Here's some code:

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

There are 1 best solutions below

1
On BEST ANSWER

If you are using Nimbus on the latest master then you must enable ARC or you will get memory leaks.