1

iOS アプリのメモリ割り当てでプロファイラーを実行していますが、現在 8 MB のメモリが作成されており、まだアプリに存在していることを検出しています。明らかに何か問題があります。そこでドリルダウンして、お見せできる画像を以下に示します。

ここに画像の説明を入力

なぜこれが原因なのか分かりますか?これは自動解放されたオブジェクトのようですが、メモリに住んでいるのではなく、解放するべきではありませんか?

関数parseTagsInCommentを呼び出す方法は次のとおりです。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    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];


        [UIView animateWithDuration:0.3 animations:^{
            [weakSelf.commentsText_ setAlpha:1.0];
            [weakSelf.commentsPostedTime_ setAlpha:1.0];
        } completion:^(BOOL finished){
            [weakSelf parseTagsInComment];
        }];
    });
    [pool release]; 
});
4

1 に答える 1

1

関数parseTagsInCommentは、いくつかのデリゲートメソッドを使用して呼び出されるか、(メインスレッドではなく)ワーカースレッドの実行パスから呼び出されると思います。

したがって、関数の最初の行で自動解放プールを作成し、最後の行でプールを破棄する必要があります。

-(void) parseTagsInComment
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   //Body of your function
   [pool release];
}
于 2012-07-24T05:34:33.560 に答える