Search code examples
iphoneobjective-cmemory-leaksnsxmlparsernsmutablestring

NSCFString appendString leak while parsing xml


I am having trouble removing leaks from an iPhone app that i'm working on. I am parsing an xml feed to get data. Here is the code I am using to parse

[[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0]; 
    NSData *xml = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"url link"]];
    self.parser = [[NSXMLParser alloc] initWithData:xml];   


[self.parser setDelegate:self];
[self.parser parse];
[self.parser release];
self.parser=nil;

And the parsing code

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if(![elementName compare:@"item"])
{tempElement = [[XMLElement alloc] init];
}
else if(![elementName compare:@"title"])
{
    self.currentAttribute = [NSMutableString string];
}

else if(![elementName compare:@"link"])
{
    self.currentAttribute = [NSMutableString string];
}
else if(![elementName compare:@"comments"])
{
    self.currentAttribute = [NSMutableString string];
}
else if(![elementName compare:@"pubDate"])
{
    self.currentAttribute = [NSMutableString string];
}
else if(![elementName compare:@"category"])
{
    self.currentAttribute = [NSMutableString string];
}

else if(![elementName compare:@"description"])
{
    self.currentAttribute = [NSMutableString string];
}}

I am getting a leak on each

self.currentAttribute = [NSMutableString string];

and on

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{NSString *strAppend = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([strAppend length] > 0) {
    [self.currentAttribute appendString:string];
}

}

Any help is appreciated. Thanks in advance


Solution

  • Thanks a lot but, i was not calling the dealloc function inside my object class. Adding this function and releasing all strings using [self.mystring release] solved the problem