1

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];
}
4

1 に答える 1

3

viewController が fav に == で終わらない場合、fav は解放されません。viewController を fav と等しくなるように設定していないため、解放されません。[fav release]外に移動ifすれば大丈夫です。

または、[fav release]完全に削除して、次のように autorelease を使用します。

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

于 2011-04-25T17:43:47.590 に答える