This is a continuation of Why do we have to set __block variable to nil?
basically using block can cause retain cycle in ARC and I still don’t quite get it why
-(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?
}];
}];
}
If you don’t know if you have a retain cycle or not, you should run your code under the “Leaks” tool in Instruments and it will tell you about any leaks or retain cycles.
Also note that in the most recent version of Xcode, the compiler will generate a warning for you if you create one of these parent/block cycles.
In your case you probably don’t need to worry.
dicdoes not retain the block that references it, so there is no cycle here. But the best way to check is with the Leaks/Allocations instrument.