图片下载开销
我的应用程序有一个 UITableView。它的单元使用 AFNetworking 从 tumblr 下载图片。这实际上确实有效,但我注意到,一旦我开始下载图片,我的应用程序就需要 5 MB 以上的内存。我首先认为这是泄漏,但是,我的应用程序没有泄漏。因此,我检查了 Instagram 等的内存使用情况,发现一旦我开始下载帖子,它们也需要更多内存。
所以我想知道为什么下载图像需要这么大的开销?或者我完全错了,我的应用程序无法运行?
My app has an UITableView. Its cells downloads pictures from tumblr using AFNetworking. This actually does work but I noticed that my app need like 5 MB more of memory as soon as I start downloading pictures. I first though that it's a leak, however, my app doesn't have a leak. So I checked the memory usage of instagram and such and noticed that they need more memory too, as soon as I start downloading posts.
So I'm wondering why downloading images involves such a big overhead? Or am I totally wrong and my app's not working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该内存开销是 UIImageView 中显示的图像的数据。
UIImage
解压缩原始编码(JPEG、PNG 等)并将其光栅化为易于绘制到屏幕的内部位图表示形式。这就是为什么与从服务器下载的资源大小相比,您的内存开销可能看起来很大。也就是说,请确保将 AFNetworking 更新到 master 的
HEAD
,因为它包含一个修复程序,可减少UIImageView
类别方法的内存占用。That memory overhead is the data of the images being displayed in
UIImageView
s.UIImage
decompresses the original encoding (JPEG, PNG, etc.) and rasterizes it into an internal bitmap representation that is easily drawn to the screen. This is why your memory overhead may seem large as compared to the size of the assets downloaded from the server.That said, make sure to update AFNetworking to
HEAD
of master, as it includes a fix that reduces the memory footprint of theUIImageView
category methods.