-1

It seems like there is memory leak in this piece of code.I am using this to parse XML data.

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI  qualifiedName:(NSString *)qualifiedName 
 attributes:(NSDictionary *)attributeDict
 {
 currentElement = [[elementName copy]autorelease];
if ([elementName isEqualToString:@"value1"]) {
    self.currentString =[NSMutableString string];
}


else if ([elementName isEqualToString:@"value2"]) {
    self.currentStringName =[NSMutableString string];
}
}   

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:@"value1"]) {
    [currentString appendString:string];
}

else if ([currentElement isEqualToString:@"value2"]) {
    [currentStringName appendString:string];
}

}

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

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

    }
   else if ([elementName isEqualToString:@"value2"])
   {
   }

2 Answers 2

1

You may want to make a little research of the style "NSXMLParser leak". Like a few other pieces of the SDK, NSXMLParser is a broken dam. I dont see in your code (after, I must say, a very quick glance) any leaks... I mean compared to what you'll find in NSXMLParser. And unfortunately, you can't do anything about them.

So, basically, if Instruments, for example, is reporting leaks with your code, don't be ashame: NSXMLParser is responsible.

If you have the chance, don't hesitate to keep control of the objects you create (and avoid autorelease), it's way easier to manage in my opinion (but...some could disagree!).

1
  • 1
    +1 No leaks in the above, but I've also heard reports of NSXMLParser itself leaking pretty badly. Jun 13, 2011 at 3:55
0

Try using other XML Parsers like touchXML or KissXML. NSXML Parser does have leaks inside the framework.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.