(iphone)UIImageView setImage:泄漏?
我正在通过 [self setImage: newImage] 更改 UIImageview 的图像;
看起来每次我用 newImage 这样做时,先前的图像似乎都没有被释放。
替换 UIImageView 图像的正确方法是什么?
谢谢
i'm changing image of UIImageview by [self setImage: newImage];
Looks like every time I does that with newImage, prior image doesn't seem to be released.
What's the correct way to replace image of UIImageView?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,UIImageView setImage 确实泄漏了!
实际上,泄漏的是 CGImage,而不是 UIImage(如仪器“分配”所示)
我使用 BrutalUIImage 而不是 UIImage
Yes, UIImageView setImage does leak!
Actually, leaks CGImage, not UIImage (as instrument "allocation" shows)
I use BrutalUIImage instead of UIImage
UIImageView setImage:
永远不会泄漏,除非您传递的图像没有被释放。如果您将自动释放的图像分配给图像视图,您的代码不会泄漏,如下所示。
但是,如果您将映像分配到某处,则必须手动释放它。
UIImageView setImage:
never leaks, unless the image you are passing doesn't get released.Your code wont leak, if your are assigning an autoreleased image to the image view, something like the following.
But, if you are allocating the image somewhere, you have to release it manually.
你的 BrutalUIImageVIew 类真的很有趣,但是通过使用 UIImage“drawInRect:”方法绘制图像,我丢失了 PNG 文件的透明区域。
你知道如何绘制图像,保持PNG透明吗?
(当然,不使用 UIImageVIew 会在调用“setImage:”时泄漏 CGImage)
Your BrutalUIImageVIew class is really interesting, but by drawing the Image using UIImage "drawInRect:" method, i loss the transparent areas of my PNG file.
Do you know how to draw the image, keeping the PNG transparence ?
(Of course, not using UIImageVIew wich leaks the CGImage while calling "setImage:")
是的 UIImageView setImage 确实泄漏了!
如果您循环浏览一堆图像,
您可以看到仪器上的内存使用量不断增加。
这似乎是某种缓存,因为之后
循环浏览所有图像内存使用量将趋于平稳。
正确的,或者至少是无泄漏的方法是:
我在我的代码上验证了这一点,因为我的应用程序循环了很多
大图像文件。
Yes UIImageView setImage indeed leaks!
If you cycle through a bunch of images with
you can see on instruments memory usage increasing.
This seems to be some kind of caching going around since after
cycling through all the images memory usage will go flat.
The correct, or at least, the non leaky way to do it is:
I verified this on my code as my APP was cycling through a lot
of large image files.