1

I have a UIImageView property in my view controller set to "assign". Every time I hit a button, I set the image in the view to something new. Due to the way I am using another component, I have to removeFromSuperView and release the UIImageView every time I change images and then re add it. This doesn't seem to be contributing to the memory problem-- when using the existing UIImageView and not releasing it the memory still goes up (but there are sizing issues, which is why I am recreating it).

For some reason, using setImage will increase the memory usage of the app by about 0.8mb (the size of the image). When I do NOT set an image, the memory seems to stay relatively constant. Any ideas why?

[self.pictureView setImage: img]; [self.pictureView setFrame: CGRectMake(0,0,[img size].width, [img size].height)]; [img release]; 

2 Answers 2

1

I think you are leaking the UIImageView, and when you leak the UIImageView, you are leaking the image in it.

It depends how you recreate the UIImageView. Be sure that you are releasing the old image view before setting the new one to the property.

It may be best to set the property as retain, because when you set new value to retain property, it releases the old instance.

Sign up to request clarification or add additional context in comments.

3 Comments

I've also tried it as retain and it doesn't seem to help... I am doing a removeFromSuperView and release directly before the shown code, then I also re init the view like this: self.pictureView = [[UIImageView alloc] init];
hmm, I think this is causing double-retain of the value. alloc retains it once, the retain property retains it twice. Try calling autorelease after "alloc] init]"
Hey, that (half) fixed it :D There is one more leak, but I think it is unrelated. Thanks!
0

Maybe set the UIImageView to nil before setting the image to clear out the reference?

pictureView.image=nil; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.