开发者

UIImageView Memory Problem

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 recre开发者_如何学JAVAating 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];


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.


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

pictureView.image=nil;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜