-1

My NSXMLParser is leaking and I don't know why! Instrument is saying, in the extended details, that the source is 100% from [Parser parse];

Picture: Instruments leaks

This is my code for allocating and releasing the NSXMLParser:

NSURL *xmlURL = [NSURL URLWithString:@"http://www.website.com/link.xml"];
NSData * dataXml = [[NSData alloc] initWithContentsOfURL:xmlURL];
Parser = [[NSXMLParser alloc] initWithData:dataXml];
[dataXml release];
Parser.delegate = self;
[Parser parse];
[Parser release];

The delegate methods

  //Standard function parser: reading open tag
    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
        attributes:(NSDictionary *)attributeDict{ 
        currentElement = elementName;
        if ([elementName isEqualToString:@"item"]) {
            xmlArray = [[NSMutableDictionary alloc] init];
        }

    }



    //Standard function parser: reading string
    - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
        if ([currentElement isEqualToString:@"created_time"]){
            valueKey = [xmlArray valueForKey:currentElement];
            if(nil != valueKey) 
            {
                valueKey = [valueKey stringByAppendingString:string];
            }else
            {
                valueKey = string;
            }
            [xmlArray setObject:valueKey forKey:currentElement]; 
        }
        if ([currentElement isEqualToString:@"message"]){
            valueKey = [xmlArray   valueForKey:currentElement];
            if(nil != valueKey) 
            {
                valueKey = [valueKey stringByAppendingString:string];
            }else
            {
                valueKey = string;
            }
            [xmlArray setObject:valueKey forKey:currentElement]; 
        }
        if ([currentElement isEqualToString:@"picture"]){
            valueKey = [xmlArray valueForKey:currentElement];
            if(nil != valueKey) 
            {

            }else
            {
                valueKey = string;
            }
            [xmlArray setObject:valueKey forKey:currentElement]; 
        }
    }


    //Standard function parser: reading close tag
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
      namespaceURI:(NSString *)namespaceURI
     qualifiedName:(NSString *)qName{ 
        if ([elementName isEqualToString:@"item"]) {
            Post *newPost = [[Post alloc] init];
            newPost.created_time = [xmlArray objectForKey:@"created_time"];
            newPost.message = [xmlArray objectForKey:@"message"];
            newPost.picture = [xmlArray objectForKey:@"picture"];
            [containerArray addObject:newPost];
            [xmlArray release];
            [newPost release];
        }
    } 
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jos
  • 2,421
  • 5
  • 26
  • 30
  • 1
    Have you double-checked your memory management in the delegate methods? A leak in one of them could show as coming from `[Parser parse];` – AC2MO Jun 10 '11 at 14:43
  • Is this leak reported in the simulator or on a device? If it's the simulator, test again on a device - the simulator sometimes gives false leaks. – deanWombourne Jun 10 '11 at 14:45
  • Did you mean the methods like didStartElement and son? I've checked them but can post them to be sure.. – Jos Jun 10 '11 at 14:47
  • It's on the simulator, can't test on the device at the moment. But will try that in a couple of hours... – Jos Jun 10 '11 at 14:48
  • It gives the same leaks on the iPhone... – Jos Jun 11 '11 at 07:53

1 Answers1

1

I suspect that the leak is occurring inside your didStartElement or didEndElement callbacks. Please post these up so that we can check.

Alex
  • 8,801
  • 5
  • 27
  • 31