I want to display some images, when image is not available I want to show a default one. When using the analyze functionality I get warnings about a potential leak. I do under stand that when using imageNamed there is no memory allocated, what would be a nice workaround ? See below a part of my code
if (!isMyFileThere){
image = [UIImage imageNamed:@"default.png"];
}
else{
image = [[UIImage alloc] initWithContentsOfFile:pngFilePath];
}
This is autoreleased
This is not
You need to do this :
The rule is if your method name begins with
alloc
,new
,copy
ormuteableCopy
you own it and need to release it yourself, either withrelease
or withautorelease
. Anything else isn't yours so you mustn't release it.If you call
retain
on an object, you mustrelease
(orautorelease
) it the same number of times :)