2010-02-25 5 views
0

내 응용 프로그램에는 네트워킹 작업을 처리하는 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]; 
} 
+1

흠. 'if (! self.error) self.error = nil'은 피곤한 눈으로 보이지 않는 것처럼 보입니다 ... 마찬가지로'self.response' 물건들도 마찬가지입니다. – Dirk

+0

이것이 내가'if (self.error! = nil)'을 선호하는 이유입니다. 더 많은 것을 요하고 마술은 적습니다. –

+0

ivars를 해제하기 위해 속성 설정자를 사용하는 경우에는 올바르지 않게 보입니다. – kennytm

답변

0

일부 추천 -dealloc 디콘에서 변수를 공개하는 데있어서 self.var = nil 세터 접근법 피하기 루터.

시도해 보았던 시도가 오래 되었습니까? [var release], var = nil 접근 방법을 시도해 보셨습니까?

+0

예. 내가 그것을 해제하는 경우, 프로그램 충돌, 나는 할당이 해제 된 객체에 메시지를 전송하고 말하는 것을 계속하는 경우입니다. 그러나 내가 그것을 풀지 않으면, 악기에 누출이 나타납니다. –

+0

self.var = nil의 문제점은 무엇입니까? – DenNukem

+0

이것이 나쁜 생각 인 이유를 설명하는 블로그 게시를 찾을 수 있는지 확인해 보겠습니다. 어쩌면 제가 언급하고있는 게시물을 알고있는 사람도 먼저 발견하면 게시 할 수 있습니다. –

관련 문제