Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective C, libxml2 memory leak when parsing xml
    text
    copied!<p>I am relatively new to objective C and coming from Java the whole memory management didn't completely got to me.</p> <p>I am using libxml2 to parse xml data and when I run my program with performance tools I get memory leaks and it says Responsible Library is libxml2.2.dylib.</p> <p>Below the code where I use the xml library. Does anyone see obvious mistakes I do? Let me know if you need more details.</p> <p>Cheers, Stephan</p> <pre><code>- (void)fetchedXML:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)retrievedData error:(NSError *)error{ if (retrievedData) { if(error==nil){ NSString *xpathQueryString = nil; NSArray *nodes = nil; //get total amount of persons xpathQueryString = @"//data/Person"; nodes = PerformXMLXPathQuery(retrievedData, xpathQueryString); int personCount = [nodes count]; for (int i=1; i&lt;=personCount; i++) { NSString *position = [NSString stringWithFormat:@"%d", i]; NSArray *matchNodes = nil; xpathQueryString = [NSString stringWithFormat:@"//data/Person[%@]/FirstName/text()", position]; matchNodes = PerformXMLXPathQuery(retrievedData, xpathQueryString); NSString *personFirstName = [XMLHelper fetchContent:matchNodes]; xpathQueryString = [NSString stringWithFormat:@"//data/Person[%@]/LastName/text()", position]; matchNodes = PerformXMLXPathQuery(retrievedData, xpathQueryString); NSString *personLastName = [XMLHelper fetchContent:matchNodes]; xpathQueryString = [NSString stringWithFormat:@"//data/Person[%@]/Job/text()", position]; matchNodes = PerformXMLXPathQuery(retrievedData, xpathQueryString); NSString *personJob = [XMLHelper fetchContent:matchNodes]; [Person storePerson:managedObjectContext personId:position firstName:personFirstName lastName:personLastName job:personJob]; } } } } </code></pre> <p>That's the code in the LinkHelper class.</p> <pre><code>+ (NSString *)fetchContent:(NSArray *)nodes { NSString *result = nil; for ( NSDictionary *node in nodes ) { for ( id key in node ) { if( [key isEqualToString:@"nodeContent"] ) { result = [node objectForKey:key]; } } } return result; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload