Potential leak The result of the analyzer will not disappear

I have this method, and the analyzer tells me that there is a potential leak of the mutable array itemsArray. I added the appropriate one releaseat the end of the method, but the result of the analyzer remains.

- (void)addCategory:(NSString*)category {
    NSMutableArray *itemsArray = [[NSMutableArray alloc] initWithCapacity:1];

    if (category) {
        [[APP_DELEGATE itemsDictionary] setObject:itemsArray forKey:category];  
    }

    [self dismissModalViewControllerAnimated:YES];
    [itemsArray release];
}

How can i fix this?

Thank.

+3
source share
2 answers

This code does not cause problems with the analyzer:

static NSMutableDictionary *itemsDictionary;

- (void)addCategory:(NSString*)category {
    NSMutableArray *itemsArray = [[NSMutableArray alloc] initWithCapacity:1];

    if (category) {
        [itemsDictionary setObject:itemsArray forKey:category];  
    }

    [self dismissModalViewControllerAnimated:YES];
    [itemsArray release];
}

Can you post the exact wording (or perhaps a screenshot) of the warning you see?

+1
source

[itemsArray release] [self rejectModalViewControllerAnimated: YES];

0

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


All Articles