Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-20-2009, 07:14 AM   #1 (permalink)
krille
New Member
 
Join Date: Jun 2009
Posts: 2
Question iPhone memory leak in xml parser

Hi everyone,
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 methods:

Code:
for(int counter = 0; counter < [item childCount]; counter++) {
	CXMLNode *child = [item childAtIndex:counter];
	if([[child name] isEqualToString:@"PRODUCT"]) 
	{
		NSMutableDictionary *product = [[NSMutableDictionary alloc] 
						init];
		for(int j = 0; j < [child childCount]; j++) {
			CXMLNode *grandchild = [child childAtIndex:j];
			if([[grandchild stringValue] length] > 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;
		}
		//DebugLog(@"ADD allgemein %@",product);
		[product release];
	}
}
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).
Instruments points me to this line in CXMLNode.m, when I dig into a leaked object:
Code:
theStringValue = [NSString stringWithUTF8String:(const char *)theXMLString];
if ( _node->type != CXMLTextKind )
	xmlFree(theXMLString);
}

return(theStringValue);
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?

Any help is highly appreciated, thank you!

Last edited by krille; 06-20-2009 at 07:26 AM.
krille is offline   Reply With Quote
 

» Advertisements
» Online Users: 722
18 members and 704 guests
ADY, AppleSteve, betterlee, blueskysinger, ckgni, Domele, femenina, hasinthajanaka, ilmman, jkigel, JohniARivera, k2c, Oral B, prerna chavan, sacha1996, saqibjaan, zamoraalex2696, zom888
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,619
Threads: 89,141
Posts: 380,328
Top Poster: BrianSlick (7,110)
Welcome to our newest member, femenina
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:31 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.