I've got a memory leak that seems to be coming from my parser each time I run it, and I'm having a hard time understanding the issue! The memory leak was found with the leak performance tool.
In the header:
Code:
NSMutableString * currentNodeContent;
Starting my xml parsing element:
Code:
//----------------------------------------------
// Starting an Element
//----------------------------------------------
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if(qName) {
elementName = qName;
}
//Only init a string if we are on the right element to build it.
if ([elementName isEqualToString:@"missionname"])
currentNodeContent = [[NSMutableString alloc] init];
Here is what happens as we collect characters.
Code:
//----------------------------------------------
// Finding characters during parse
//----------------------------------------------
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[currentNodeContent appendString:string];
}
Here is the ending element, where we save the string off to a new one and then release the temp one.
Code:
//----------------------------------------------
// Ending Element
//----------------------------------------------
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(qName) {
elementName = qName;
}
if([elementName isEqualToString:@"missionname"]){
missionData[totalMissions].Name = [[NSMutableString alloc] init];
missionData[totalMissions].Name = [currentNodeContent mutableCopy];
[currentNodeContent release];
currentNodeContent = nil;
}
Pretty much when I stack trace it lights up everything in the above if statement for missionname. Even the simple appendstring gets a warning. Any thoughts? Is there anything I'm obviously doing wrong?