我有一个长的水平分页滚动视图,对于每个页面,我都放了一个全屏 UIImage.
I have a long horizontal paged scrollview, for each page, I put a fullscreen UIImage.
由于价格昂贵且无需一次添加所有 UIImage,目前我延迟加载图像(pageIndex-1 + pageIndex + pageIndex+1 的图像,使用 NSOperationQueue 仅供参考),并删除所有其他 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 超出显示范围"时,它会从其父视图中删除.
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!
p.s Dirty Size 的大幅下降是我停止滚动的那一刻.
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)
可以使用
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“内存标签70"滚动时的释放时机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!