Water7
Water7

Reputation: 505

Uiimage memory leak

.h file

UIImage *ownImg;

@property (nonatomic, retain) UIImage *ownImg;

.m file

In viewWillAppear method:

UIImage *myImage2 = [UIImage imageNamed:@"thumbnail.png"];

self.ownImg = myImage2;

That is a leak in ownImg, anyone know why it leaking?

BTW, what is the different of using self.ownImg and without the self.

Thanks.

Upvotes: 1

Views: 714

Answers (1)

No one in particular
No one in particular

Reputation: 2672

Calling

ownImg = myImage2;

is just an assignment that merely sets the pointers. But calling

self.ownImg = myImage;

will call a @synthesized setter that contains a retain. (I assume you have the @synthesize() for the ownImg.)

Because you're using a setter method that retains you'll have to release it somewhere. Try placing that in the override for the unload method, or if a non-nib class place it in the dealloc.

Upvotes: 3

Related Questions