私はiOS開発に不慣れです。バックグラウンドスレッドの実行中に問題が発生しました。私のコードでは、resetUiはメインUIスレッドで実行されていますが、画像データをフェッチして画像を更新するためにバックグラウンドスレッドを開始しています。すべて正常に動作しますが、performSelectorInBackgroundを呼び出すと、メモリがリークします。
どこが間違っているのか教えてください。また、URL(dataWithContentsOfURL)から取得しているときに画像を更新するためのより良い方法があるかどうかを提案してください。
[アップデート]
Instrumentは、perfromSelectorInBackgroundとUIImageimageWithDataで2つの別々のリークを表示しています。imageupdate(imageWithData)で何かがひどく間違っていると思います
-(void)updateData{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
profileName.text = oAuthTwitter.screen_name;
if(profilePic.image == nil){
NSString *urlString = @"https://api.twitter.com/1/users/profile_image/";
urlString = [urlString stringByAppendingFormat:oAuthTwitter.screen_name];
urlString = [urlString stringByAppendingFormat:@"?size=bigger"];
profilePic.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]];
[activityIndicator stopAnimating];
[activityIndicator release];
}
[pool drain];
}
- (void)resetUi{
if (oAuthTwitter.oauth_token_authorized) {
profilePic.hidden = NO;
profileName.hidden = NO;
NSLog(@"Resetting to authorised state");
[self performSelectorInBackground:@selector(updateData) withObject:nil];
}else{
NSLog(@"Resetting Twitter UI to non-authorized state.");
profilePic.hidden = YES;
profileName.hidden = YES;
}
}