Reputation: 5929
Memory need to be release for alloc, retain and copy. My question is for following situation where I retain the UIImage property, but it was autorelease by the function of imagedNamed. Should I still release following variable?
@property (nonatomic, retain) UIImage *image;
self.image = [UIImage imageNamed:@"image.png"];
Thanks!
Upvotes: 2
Views: 145
Reputation: 170849
In your code you don't use your property but assign autoreleased UIImage object to your iVar directly, so you need
retain your image (or better actually use property) - otherwise your image object will be destroyed when you exit current scope and accessing it in other methods will result in an error. So use:
self.image = [UIImage imageNamed:@"image.png"];
Release your image in dealloc method
Upvotes: 4