UIImageView内存问题
我的视图控制器中有一个 UIImageView 属性设置为“分配”。每次我按下按钮时,我都会将视图中的图像设置为新的图像。由于我使用另一个组件的方式,每次更改图像时,我都必须removeFromSuperView并释放UIImageView,然后重新添加它。这似乎不会导致内存问题——当使用现有的 UIImageView 并且不释放它时,内存仍然会增加(但存在大小问题,这就是我重新创建它的原因)。
由于某种原因,使用 setImage 会使应用程序的内存使用量增加约 0.8mb(图像的大小)。当我不设置图像时,内存似乎保持相对恒定。有什么想法吗?
[self.pictureView setImage: img];
[self.pictureView setFrame: CGRectMake(0,0,[img size].width, [img size].height)];
[img release];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你正在泄漏 UIImageView,当你泄漏 UIImageView 时,你正在泄漏其中的图像。
这取决于您如何重新创建 UIImageView。确保在将新图像视图设置为属性之前释放旧图像视图。
最好将该属性设置为保留,因为当您为保留属性设置新值时,它会释放旧实例。
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.
也许在设置图像之前将 UIImageView 设置为 nil 以清除引用?
Maybe set the UIImageView to nil before setting the image to clear out the reference?