[[UIImage alloc] initWithContentsOfFile:path]
メソッドが画像を初期化できない場合は nil を返します。次のコードは、割り当てられた UIImage を解放していません。画像が[image release]
行に nil であるためです。
UIImage* image = [[UIImage alloc] initWithContentsOfFile:path];
if(image)
{
....
}
//Here image is nil and not releases allocated UIImage.
[image release];
これは本当にメモリリークですか?
init が nil を返す場合、どのようにオブジェクトを解放する必要がありますか? UIImage* image = [[UIImage alloc] initWithContentsOfFile:path]; を行う場合
init が失敗するため、image は nil です。[image release] は [nil release] と同じです。エラーはありませんが、何も解放されていません。