UIImageView隐藏时消耗内存? (iOS)
UIImageView隐藏时需要内存吗? 对于 alpha=0.0 同样的问题
我经常处理隐藏图像,我想知道它们是否仍然消耗内存。
更具体地说,我想知道表视图的情况。
谢谢
Does UIImageView requires memory when it is hidden?
Same question for alpha=0.0
I work a lot with hidden images, and I wonder if those still consume memory.
More specifically I would like to know that for tableview.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然如果它有一个图像加载到视图中,它会加载,因为
UIImageView
只是一个UIView
,它有一个UIImage< /code> @property 带有
retain
属性,以便保留图像。视图是否可见这一事实当然不会改变任何东西,并且希望因为否则如果您再次将
UIImageView
设置为可见,iOS 将无法再次加载UIImage
(一旦image
属性影响到UIImageView
,UIImageView
就无法知道图像的来源,是否是从文件加载的,一个以编程方式生成的 URL,...?),甚至如果它确实知道重新加载它会很痛苦(可能需要一些时间来加载和解码)如果您不使用
UIImageView
的图像,至少设置其image< /code> 属性设置为
nil
以隐藏它(如果需要重新显示图像,请自行重新加载/重新影响图像,但如果在UITableView
中使用它,则由于的回收/再利用机制UITableViewCells
它可能永远不会是相同的图像来设置)Of course if it has an image loaded into the view, it does, because
UIImageView
is simply aUIView
that has aUIImage
@property with theretain
attribute so it retains the image.The fact that the view is visible or not does not change anything of course, and hopefully because otherwise iOS couldn't load the
UIImage
again if you set theUIImageView
visible again (once theimage
property is affected to theUIImageView
, theUIImageView
can't know the source of the image, was it loaded from a file, an URL, generated programatically, ...?), and even if it did know it would be a pain to reload it (could take some time to load and decode)If you don't use an
UIImageView
's image, at least set itsimage
property tonil
to hide it (and reload/reaffect the image again yourself if you need to redisplay it, but if it is used in aUITableView
because of the recycling/reuse mechanism of theUITableViewCells
it will probably never be the same image to set anyway)