UIImageView / UIImage“Memory Tag 70”滚动时释放时间 [英] UIImageView/UIImage "Memory Tag 70" release timing when scrolling

查看:87
本文介绍了UIImageView / UIImage“Memory Tag 70”滚动时释放时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的水平分页滚动视图,对于每个页面,我都放了一个全屏UIImage。

I have a long horizontal paged scrollview, for each page, I put a fullscreen UIImage.

因为它很贵而且没必要一次添加所有UIImage,目前我懒得加载图像(pageIndex-1 + pageIndex + pageIndex + 1的图像,使用NSOperationQueue FYI),并删除所有其他UIImageViews。

As it is expensive and not necessary to add all UIImage at once, currently I lazy load the images (pageIndex-1 + pageIndex + pageIndex+1 's images, using NSOperationQueue FYI), and remove all other UIImageViews.

报告的内存使用情况来自Instrument的正常使用是可以接受的,但我发现如果我继续滚动(连续切换30页),脏内存会不断增加,特别是内存标签70,我相信它是来自UIImage的原始数据。一旦我停止触摸应用程序3到4秒,所有内存标签70将自动释放。

The memory usage reported from Instrument is acceptable with normal usage, but I discover if I keep scrolling (switching between 30 pages continously), the Dirty memory would keep increasing, especially "Memory Tag 70" which I believe it is the raw data from UIImage. Once I stop touching the app for 3~4 seconds, ALL "Memory Tag 70" would be released automagically.

我已将NSLog放在几个地方而且我是当UIImageViews超出显示范围时,确保将UIImageViews从超级视图中删除。

I've put NSLog in several places and I'm sure the UIImageViews are removed from its superview when it is out of the "display range".

滚动是否阻止主循环释放这些内存?我该怎么做才能防止这种情况发生?谢谢!

Is scrolling preventing the main loop to release those memory? What could I do to prevent such condition? Thanks!

ps巨大的Dirty Size中的drop is是我停止滚动的时刻。

p.s The huge drop in Dirty Size is the moment when I stop scrolling.

推荐答案

(只是一个猜测,我远离Xcode到测试它,并假设一个非ARC环境)

(Just a guess, I'm far from an Xcode to test it, and assuming a non-ARC environment)

而不是 [otherImageView removeFromSuperview] ,你可以使用

UIImage *image = [otherImageView.image retain];
otherImageView.image = nil;
[image release]; // the image won't go to the main autorelease pool
[otherImageView removeFromSuperview]; // No one has references to otherImageView, so it goes to the autorelease pool

避免图像进入到自动释放池。

To avoid the image going to the autorelease pool.

这篇关于UIImageView / UIImage“Memory Tag 70”滚动时释放时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆