0

これは、__block 変数を nil に設定する必要があるのはなぜですか?の続きです。

基本的にブロックを使用すると、ARCで保持サイクルが発生する可能性がありますが、その理由はまだよくわかりません

http://developer.apple.com/library/mac/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226-CH1-SW11

-(void)getReviewAndView{
    if(![[GrabClass grab] cekInet]){return;}
    CM(@"get review and view");
    self.viewlbl.text=@"0 view";
    self.reviewlbl.text=@"0 review";

    Business * businessReviewed = [BNUtilitiesQuick currentBusiness];

    NSString *alamat=[NSString stringWithFormat:@"http://...",businessReviewed.ID];

    CLog(@"alamat:%@", alamat);

    __block NSDictionary * dic = nil;


    [Tools doBackground:^{
        dic=(NSDictionary *)[GrabClass JsonParser:alamat]; //dic get set here
        [Tools doForeGround:^{
            NSString *countView= [[dic objectForKey:businessReviewed.ID] objectForKey:@"CountViews"];

            CLog(@"countView:%@", countView);
            NSString *countReview=[[dic objectForKey:businessReviewed.ID] objectForKey:@"Review"]; //dic get used here
            NSString * reviews=@"review";
            NSString * view=@"view";


            //blablabla

            self.viewlbl.text=[NSString stringWithFormat:@"%@ %@",countView,view ];
            self.reviewlbl.text=[NSString stringWithFormat:@"%@ %@",countReview,reviews];
            dic =nil; //should this be called? What happen if it doesn't?
        }];
    }];
}
4

1 に答える 1

1

保持サイクルがあるかどうかわからない場合は、Instrumentsの「リーク」ツールでコードを実行すると、リークまたは保持サイクルが通知されます。

また、最新バージョンのXcodeでは、これらの親/ブロックサイクルのいずれかを作成すると、コンパイラーが警告を生成することにも注意してください。

あなたの場合、おそらく心配する必要はありません。dicそれを参照するブロックを保持しないため、ここにサイクルはありません。ただし、チェックする最良の方法は、リーク/割り当て装置を使用することです。

于 2012-06-12T15:56:32.860 に答える