Search code examples
objective-cmemory-managementmemory-leaksclang-static-analyzer

Can't find a leak from the Static Analyzer


I am getting some errors from the Clang Static Analyzer saying that I have a few leaks from the following code. However I am unable to find the leak. Please tell me where the leak is.

 Favourites *fav = [[Favourites alloc] initWithNibName:@"Favourites" bundle:nil];
if (viewController == fav) {
    [fav doHud];
    [fav release];
}

Solution

  • fav won't be released if viewController does not end up == to fav. You are not setting viewController to be equal to fav so it won't release. Move[fav release] outside the if and you should be fine.

    or get rid of the[fav release] altogether and just use autorelease like:

    Favourites *fav = [[[Favourites alloc] initWithNibName:@"Favourites" bundle:nil] autorelease];