views:

31

answers:

1

.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.

+2  A: 

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.

No one in particular
I do synthesized ownImg.In viewDidUnload I write self.ownImg = nil;In dealloc [ownImg release];Maybe is because I'm assigning the value in viewWillAppear so it cause the memory leak?So I should check if the self.ownImg != nil and then release it before assign it again?Thanks.
Water7
Just use self.owning = newThing; That will release the old, retain the new, and set the pointer to the new address. These synthesized methods hide a lot of code.
No one in particular