내 응용 프로그램에는 네트워킹 작업을 처리하는 ServerRequest라는 NSOperation 클래스가 있습니다. 악기에 따르면, 그것은 미친 것처럼 새고 있습니다. 또한 계측기는 NSOperation이 아니더라도 요청을 작성하는 코드가 유출되었다고 말합니다. 그러나 나는 자동 풀 풀을 설정하는 측면에서 애플의 조언을 따랐다. 그래서 나는 그 문제가 무엇인지 이해하지 못한다. 누구든지 도와 줄 수 있습니까?Iphone - NSOperation 내에서 누수가 혼동 스럽습니다.
-(void) main {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
self.data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; // lots of leakage here
[self postResult]; // leakage here too
[pool release];
}
과 (누출되지 않음) postResult 방법 :
내 코드의 일부는 다음과 같습니다
-(void) postResult {
// error handling code here
if (![self isCancelled])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *resultDictionary = [[NSMutableDictionary alloc]init];
if (self.data!=nil)
[resultDictionary setObject:self.data forKey:kDataKey];
if (self.response!=nil)
[resultDictionary setObject:self.response forKey:kResponseKey];
if (self.error!=nil)
[resultDictionary setObject:self.error forKey:kErrorKey];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
NSNotification *notification = [NSNotification notificationWithName: kDownloadCompleteName object: self userInfo: resultDictionary];
[resultDictionary release];
[center postNotification: notification];
[pool drain];
}
}
마지막으로, 할당 해제 :
- (void) dealloc {
self.request = nil;
self.data = nil;
self.mutableData = nil;
if (!self.error)
self.error = nil;
if (!self.response)
self.response = nil;
[super dealloc];
}
흠. 'if (! self.error) self.error = nil'은 피곤한 눈으로 보이지 않는 것처럼 보입니다 ... 마찬가지로'self.response' 물건들도 마찬가지입니다. – Dirk
이것이 내가'if (self.error! = nil)'을 선호하는 이유입니다. 더 많은 것을 요하고 마술은 적습니다. –
ivars를 해제하기 위해 속성 설정자를 사용하는 경우에는 올바르지 않게 보입니다. – kennytm