UIImageView/UIImage“内存标签70"滚动时的释放时

UIImageView/UIImage quot;Memory Tag 70quot; release timing when scrolling(UIImageView/UIImage“内存标签70滚动时的释放时机)
本文介绍了UIImageView/UIImage“内存标签70"滚动时的释放时机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长的水平分页滚动视图,对于每个页面,我都放了一个全屏 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"滚动时的释放时机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
quot;Server certificate untrustedquot; error in iPhone application(“服务器证书不受信任iPhone应用程序中的错误)
Comparing an NSDate to [NSDate date](将 NSDate 与 [NSDate 日期] 进行比较)