The static analyzer is showing up a leak in this block of code (specifically the link with the copy in it):
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"item"])
{
[elements setObject:title forKey:@"title"];
[elements setObject:date forKey:@"date"];
[elements setObject:summary forKey:@"summary"];
[elements setObject:link forKey:@"link"];
[posts addObject:[elements copy]];
}
}
I tried releasing the copied object but I still get the warning. Am I missing something?
Thanks
You created new copy which you don’t release.
This returns new
elementsobject with ref count 1 which you are responsible to deallocate since you’ve just created a copy:In this line you add the new created copy to
postswhich looks like collection.All collections retain new values, so you pass your new copy with ref count 1 and posts increase the ref count to 2 by retaining it.
On release
postswill send to each elementreleasewhich will decrement ref count to 1 soelementsdoes not get deallocated and you end up with memory leak.Remove the
copyand see if that helps: