iPad iOS内存管理 - 如何释放“真实内存” UIImageViews,UIScrollViews使用? [英] iPad iOS memory management - how to free up "Real Memory" used by UIImageViews, UIScrollViews?

查看:518
本文介绍了iPad iOS内存管理 - 如何释放“真实内存” UIImageViews,UIScrollViews使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的某个应用程序存在内存问题,并且我已经确定了仪器>活动监视器中定义的真实内存可能是罪魁祸首。

I'm having memory issues with one of my apps and I've identified "Real memory" as defined in Instruments> Activity monitor as a possible culprit.

我的应用在UIScrollViews 中分配大型UIImages。有一个CIImageFilter应用于其中一个图像。活动监视器显示,在第一次推送包含带有大图像的滚动视图的视图控制器时,实际内存使用量将跳至300mb左右。后续推送/弹出将其提升至约500mb:

My app allocates large UIImages within UIScrollViews. There's a CIImageFilter applied to one of the images. Activity monitor shows that upon the first pushing of the view controller containing scrollviews with large images, the real memory use jumps to around 300mb. Subsequent pushes/pops raise it to about 500mb:

我读到Live Bytes不计算纹理和CALayers使用的内存,所以我的问题是:如何正确释放我的Image / Scrollviews的CALayers使用的内存?

I read that "Live Bytes" does not count memory used by textures and CALayers, so my question is: How do I properly release memory that is used by CALayers of my Image/Scrollviews?

查看右侧的实际内存使用情况蓝色饼图:

See the real memory usage blue pie chart on the right:

真实和虚拟内存都是最高的对于这个过程:

Both real and virtual memory are the highest for this process:

困扰我的是我在弹出控制器时试图清理我的大型滚动视图和图像,实时字节的数字下降到约5mb ,而真正的备忘录ry保持高位(~500 mb):

What bothers me is that I'm trying to clean up my large scrollviews and images when popping that controller, and the numbers for the "Live bytes" go down to about 5mb, while "Real Memory" stays outrageously high(~500 mb):

ContainerScrollView* container = ...;
[container.view removeFromSuperview];
container.view = nil;

以下是分配分析:

Here's the allocations profiling:

推荐答案

我发现一个人遇到过类似情况问题在这里:

I found a person experiencing a similar issue here:

神秘的CoreImage使用ARC的内存泄漏

答案(我真的希望如此)似乎开始使用 NSData dataWithContentsOfFile:然后创建一个 UIImage imageWithData:。有用户选择的图像?将其写入临时文件并将其读回。我不相信任何其他图像方法,因为他们在我的12小时测试中看起来在iOS 6.1.2中对大图像视图表现得不合理。

The answer (I really hope it is) appears to start using NSData dataWithContentsOfFile: and then create a UIImage imageWithData:. Got an image a user picked? Write it to a temporary file and read it back. I do not trust any other image methods, as they, in my 12 hours of testing appear to behave irrationally in iOS 6.1.2 for large image views.

这篇关于iPad iOS内存管理 - 如何释放“真实内存” UIImageViews,UIScrollViews使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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