Memory Leak Warning I Can't Solve

The static analyzer detects a leak in this block of code (in particular, a link with a 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 to free the copied object, but I still get a warning. Did I miss something?

thank

+3
source share
2 answers

You have created a new copy that you are not releasing.

This returns a new object elementswith ref 1, for which you are responsible for the release, because you just created a copy:

[elements copy];

posts, . , ref 1 2, .

[posts addObject:[elements copy]];

posts release, 1, elements , .

copy , :

[post addObject:elements];
+5

, :

, .

, ?

    [posts addObject:[elements copy]];
    [elements release];

, .

, , , - , copy, , posts. : .

, , , , , ; , . elements, .

elements a removeAllObjects; , .

elements, XML. "elements" . "feedItemProperties" .

+3

Source: https://habr.com/ru/post/1732807/


All Articles