-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"])
   {
   }
agupta
  • 403
  • 1
  • 7
  • 17

2 Answers2

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!).

Community
  • 1
  • 1
Remy Vanherweghem
  • 3,925
  • 1
  • 32
  • 43
0

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

Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256