iOS 개발을 처음 사용합니다. 배경 스레드를 실행하는 동안 문제가 발생했습니다. 내 코드 resetUi에서 기본 UI 스레드에서 실행 중입니다. 이제 이미지 데이터를 가져 와서 내 이미지를 업데이트하는 백그라운드 스레드를 시작하고 있습니다. 모든 것은 잘 작동하지만 performSelectorInBackground를 호출 할 때 메모리가 누수됩니다.performSelectorInBackground를 사용하는 동안 메모리 누수가 발생했습니다.
내가 잘못하고있는 부분을 알려주십시오. 또한 URL (dataWithContentsOfURL)에서 가져 오는 동안 내 이미지를 업데이트하는 더 좋은 방법이 있는지 제안하십시오.
[업데이트]
기기는 2 개의 별도 누수를 UIImage imageWithData에서 perfromSelectorInBackground 이상의 다른 표시된다. 난 당신이 오히려 훨씬 더 좋은 연습입니다
[pool drain];
보다
[pool release];
를 사용한다고 생각 뭔가
-(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;
}
}
나는 그것을 바꿔 보았지만 운이 없다. – vijaykumarg
예 누출 도구를 사용하여 코드를 실행하고 있습니다. URL에서 이미지를 가져 오는 다른 방법이 있으면 나를 명확히하십시오. 나는 그것이 모든 문제를 일으키는 것 같아요. – vijaykumarg
응답에서 언급 한 activityIndicator 항목을 변경 했습니까? 또한 URL에서 이미지를 가져 오는 것과 관련하여 로직이 좋아 보이고 이것이 문제의 원인이라고 생각하지 않습니다. – Krishnabhadra