调用 nil 后 iPhone 内存没有释放
我正在使用Apple的ScrollingSuite来显示带有许多大图像的大滚动视图。(768 x1024)图像视图的图像由其中设置
controller.numberImage.image = [self.contentList objectAtIndex:page];
,numberImage是UIImageView,控制器是我在滚动视图中添加的视图控制器的对象。当页面滚动到视图之外时,我将图像设置为 nil
controller.numberImage.image = nil;
但问题是我的应用程序在滚动图像时内存不足,收到内存警告。每次显示新图像时,我都可以看到仪器工具(内存标签 70)中的内存增加,谷歌搜索结果是 ImageIO。请帮助我
提前致谢
I am using Apple's ScrollingSuite for displaying a large scrollview with a number of large images.(768 x1024) The image of an imageview is set by
controller.numberImage.image = [self.contentList objectAtIndex:page];
where, numberImage is an UIImageView and controller is an object of the viewcontroller which I am adding in the scrollview. I am setting the image as nil when the page is scrolled out of view by
controller.numberImage.image = nil;
But the problem is my app runs out of memory receiving Memory Warning when scrolled through the images. Each time a new image is shown, I can see memory increasing in instruments tool (Memory Tag 70) which on googling turns out ImageIO. Please help me with this
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试删除 imageView (
[controller.numberImage removeFromSuperview];
),然后在它即将进入视图之前将其添加回来 ([controller addSubview:[[UIImageView alloc] initWithImage:[self .contentList objectAtIndex:page]]];
)可能吗?Try removing the imageView (
[controller.numberImage removeFromSuperview];
), then adding it back before it is about to come into view ([controller addSubview:[[UIImageView alloc] initWithImage:[self.contentList objectAtIndex:page]]];
) possibly?对于此类问题,可以有各种解决方案,所以...
我认为您可以像
[controller.numberImage removeFromSuperview]
一样删除 imageview,并在需要时再次分配图像UImageView
。它可以是第一个解决方案。如果我解释一下,一次可以加载 3 个图像,然后加载当前图像、上一个图像和下一个图像。这意味着如果您想查看图像 2,则一次加载三个图像:图像 1、图像 2 和图像 3。当您滚动到下一个图像时,然后加载图像 2、图像 3 和图像 4 并释放图像 1...等等...反之亦然,用于加载图像上
最糟糕的解决方案是尝试降低图像分辨率而不改变图像的大小。
Various kinds of solution can be for such kinds of problem so...
I think you can remove the imageview like
[controller.numberImage removeFromSuperview]
and alloc the image again when you need theUImageView
.it can be first solution.At a time you can load 3 images if i explain then load the present image,previous image and next image.thats mean if you want to see the image 2 load at a time three images,image 1,image 2,and image 3. when you will scroll to next image then load image 2,image 3 and image 4 and dealloc the image 1...and so on...vice versa for loading image previous image loading.
the worst solution is try to decrease the image resolution without changing the size of the image.