2010-11-08 57 views
0

下面是我的代碼,泄漏說我得到一個NSMutableString alloc方法周圍的內存泄漏。我相信這是我簡單忽略的,讓我知道如果有人有任何想法。謝謝!內存泄漏與IPX上的NSXMLParser


-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 

    if (!currentValue) { 
     currentValue = [[NSMutableString alloc] initWithCapacity:[string length]]; 
    } 

    [currentValue setString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; 

} 

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ 

    if([elementName isEqualToString:@"phone"]){ 

     currentAgent.phone = currentValue; 
    } 

    [currentValue release]; 

    currentValue = nil; 

} 

智能體是當類被初始化時創建的自定義對象。 XML是有效的,並具有所有適當的開始/結束標籤。

回答

1

查看此代碼,我認爲您的Agent類更可能泄漏電話。假設代理使用retain作爲手機媒體資源,這會導致手機持續時間超過其應有的時間。

即使額外的保留位於其他位置,對象的創建者也會因泄漏而「記入」。

換句話說,在代理:

- (void)dealloc { 
    self.phone = nil; 
    // anything else you need to do 
    [super dealloc]; 
} 
+0

非常感謝史蒂芬,我知道這是什麼,我只是忽視。看起來,我的代理類dealloc有釋放所有屬性接受電話之一。我修改了,泄漏似乎得到了解決。謝謝! – DerekH 2010-11-09 15:32:42

+0

不客氣。我已經達到了我真正喜歡記憶問題的地步。 :) – 2010-11-09 18:02:43