title: Strange iPhone memory leak in xml parser
body: <p><strong>Update</strong>: I edited the code, but the problem persists...  </p>
  
  <p>Hi everyone,<br>
  this is my first post here - I found this place a great ressource for solving many of my questions. Normally I try my best to fix anything on my own but this time I really have no idea what goes wrong, so I hope someone can help me out.<br>
  I am building an iPhone app that parses a couple of xml files using TouchXML. I have a class XMLParser, which takes care of downloading and parsing the results. I am getting memory leaks when I parse an xml file more than once with the same instance of XMLParser.
  Here is one of the parsing snippets (just the relevant part):  </p>
  
  <pre><code>for(int counter = 0; counter &lt; [item childCount]; counter++) {  
          CXMLNode *child = [item childAtIndex:counter];
          if([[child name] isEqualToString:@"PRODUCT"]) 
          {
              NSMutableDictionary *product = [[NSMutableDictionary alloc] init];
              for(int j = 0; j &lt; [child childCount]; j++) {
                  CXMLNode *grandchild = [child childAtIndex:j];
                  if([[grandchild stringValue] length] &gt; 1) {
                      NSString *trimmedString = [[grandchild stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
                      [product setObject:trimmedString forKey:[grandchild name]];
                  }
              }
  
              // Add product to current category array
              switch (categoryId) {
                  case 0:
                      [self.mobil addObject: product];
                      break;
                  case 1:
                      [self.allgemein addObject: product];
                      break;
                  case 2:
                      [self.besitzeIch addObject: product];
                      break;
                  case 3:
                      [self.willIch addObject: product];
                      break;
                  default:
                      break;
              }
              [product release];
          }
  
      }  
  </code></pre>
  
  <p>The first time, I parse the xml no leak shows up in instruments, the next time I do so, I got a lot of leaks (NSCFString / NSCFDictionary).<br>
  Instruments points me to <strong>this part inside CXMLNode.m</strong>, when I dig into a leaked object:  </p>
  
  <pre><code>theStringValue = [NSString stringWithUTF8String:(const char *)theXMLString];
  if ( _node-&gt;type != CXMLTextKind )
     xmlFree(theXMLString);
  }
  
  return(theStringValue);  
  </code></pre>
  
  <p>I really spent a long time and tried multiple approaches to fix this, but to no avail so far, maybe I am missing something essential?  </p>
  
  <p>Any help is highly appreciated, thank you!</p>