TonyTakeshi
TonyTakeshi

Reputation: 5929

Should this variable release manually?

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

Answers (2)

Vladimir
Vladimir

Reputation: 170849

In your code you don't use your property but assign autoreleased UIImage object to your iVar directly, so you need

  1. 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"];
    
  2. Release your image in dealloc method

Upvotes: 4

Strong Like Bull
Strong Like Bull

Reputation: 11317

Yes you have to release image since you retained it.

Upvotes: 0

Related Questions