2012-01-03 2 views
0

코드에 대한 자세한 정보를 제공했습니다. checkstatusthread()은 5 초마다 호출됩니다. 아래에 사용 된 ipItemsArray 객체는 서버에서 오는 XML을 저장합니다.NSMutableArray를 사용하는 또 다른 메모리 누수

// XMLAppDelegate.h

@interface XMLAppDelegate : NSObject <UIApplicationDelegate> { 
    NSMutableString *hostStr2; 
    NSData *dataURL2; 
    NSString *playlistdata; 

} 

@property (nonatomic, retain) NSMutableString *hostStr2; 
@property (nonatomic, retain) NSData *dataURL2; 
@property (nonatomic, retain) NSString *playlistdata; 
@end 

// XMLAppDelegate.m

-(void)checkstatusthread 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    hostStr2 = [[NSMutableString alloc] initWithFormat:@"http://%@/getplaylist.php?ip=%@",yourip,restip]; 

    dataURL2 = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr2 ]]; 

    playlistdata = [[NSString alloc] initWithData:dataURL2 encoding: NSASCIIStringEncoding]; 

    ipItemsArray = [playlistdata componentsSeparatedByString:@"|^|"]; 

    [hostStr2 release]; 
    [playlistdata release]; 

    status =[ipItemsArray objectAtIndex:0]; 
    [status retain]; 

    if([[ipItemsArray objectAtIndex:0]isEqualToString:@"0001"]) 
    { 
     serverOutput1 =[ipItemsArray objectAtIndex:1]; 
     [serverOutput1 retain]; 

     nowplaying =[ipItemsArray objectAtIndex:2];  
     [nowplaying retain]; 

     tracklocation=[ipItemsArray objectAtIndex:3]; 
     [requestlocation retain]; 

     requestlocation=[ipItemsArray objectAtIndex:4]; 
     temp_app =[tracklocation intValue]; 


    } 

     [serverOutput1 retain]; 
     [nowplaying retain]; 
     [serverOutput1 retain]; 
     [nowplaying retain]; 
     [tracklocation retain]; 
     [requestlocation retain]; 

     // checkstatus() called 
     [self performSelectorOnMainThread:@selector(checkstatus) 
          withObject:nil 
         waitUntilDone:false]; 

    [pool drain]; 
} 


- (void)dealloc { 
    [dataURL2 release]; 
    [playlistdata release]; 
    [ipItemsArray release]; 
} 

NSArray *ipItemsArray = [playlistdata componentsSeparatedByString:@"|^|"]; 나에게 내가 엑스 코드 4.2에서 누수 악기를 실행 메모리 누수를 제공 라인입니다. 이 모든 가능한 일을 시도했지만 뭔가 추가해야한다고 생각합니다. 누군가 나를 도울 수 있습니까?

다음은 누출 된 개체의 스크린 샷입니다. 또한 내 애플 Dealloc 메서드를 호출하지 않는 것으로 나타났습니다. 모든 작업을 완료 한

enter image description here

+1

완료되면 playlistdata 및 hostStr2를 출시 하시겠습니까? –

+0

@ShantiK : 예, 그렇습니다. – maddy2012

+0

상태를 두 번 유지하는 이유는 무엇입니까? –

답변

1

누출 된 개체는 "상태"입니다. 나는 그것이 iVar라고 추론한다. 이 작업을 수행 할 때 :

status =[ipItemsArray objectAtIndex:0]; 
[status retain]; 

이 라인이 실행 얻을 두 번째 시간, 상태 이전에 저장된 값은 따라서 제대로 누출을 해제되지 않습니다. 당신은 이상적으로 이것을해야합니다 :

if(status) { 
    [status release]; 
} 
status =[ipItemsArray objectAtIndex:0]; 
[status retain]; 

이것은 장비에 나타난 누출을 해결할 것입니다. (ARC가 사용되지 않는다고 가정)

+0

다른 iVars에서도 동일한 작업을 수행해야합니다. 그렇지 않으면 속성을 보유하고 self.status를 사용하여 속성에 액세스하는 등의 작업을 수행합니다. 이 경우 이전 값을 직접 할당하고 해지 할 필요가 없습니다. –

0

올바른 것입니다. Leaks Instrument에 표시된 모든 누수가 현재 누수가되는 것은 아닙니다.

첫 번째 단계에서 Clang Analyzer Xcode -> 제품 -> 분석을 사용하는 것이 좋습니다. 이것은 잠재적 인 누수를 보여줍니다. 그리고이 후에는 Heapshot 분석 http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/

+0

감사합니다. 분석 결과 나에게 아무런 문제가 없다. 나는 여기에 주어진 링크를 시도하고이 방법을 사용하여 돌아올 것이다. – maddy2012

+0

Allocations 도구를 사용하여 Mark Heap 분석 포인트가이 코드 행에 다시 나타납니다. NSArray * ipItemsArray = [playlistdata componentsSeparatedByString : @ "|^|"]; ' – maddy2012

1

실제로 분석기 코드의이 라인을 가리키는 사용해야합니다

당신이 할당 아직 공개되지 않은
NSMutableString *hostStr2 = [[NSMutableString alloc] initWithFormat:@"http:// %@/getplaylist.php?ip=%@",yourip,restip]; 

.

해제해야합니다.

+0

재생 목록 데이터도 공개되지 않습니다. – WiseOldDuck

+0

'playlistdata'는 클래스 수준 이었으므로 그 점을 지적하지 않습니다. –

+0

세 가지 개체를 모두 공개합니다. 하지만 여전히 메모리 누수가 발생하고 있습니다. 다른 클래스 나 다른 솔루션을 사용해야합니까? – maddy2012