Search code examples
iphoneuiimagereleaseretain

Release a retain UIImage property loaded via imageNamed?


In my class object i've defined a (nonatomic, retain) property for UIImage. I assigned this property with an image loaded via

[UIImage imageNamed:@"file.png"];

If at some point I want to reassign this property to another image, should I have to release the prior reference?

I am confused because by the retain property I know i should release it. But because imageNamed: is a convenience method (does not use alloc), im not sure what rule to apply here.

Thanks for the insight!


Solution

  • The image is returned to you autoreleased as per the naming rules. Assigning it to a property with a retain attribute via the setter will retain it. Assigning another image to the property via the setter will release the old image and retain the new one.