iPad iOS memory management - how to free up “Real Memory” used by UIImageViews, UIScrollViews?

。_饼干妹妹 提交于 2019-12-07 03:18:29

问题


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.

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:

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:

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:


回答1:


I found a person experiencing a similar issue here:

Mysterious CoreImage memory leak using ARC

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.



来源:https://stackoverflow.com/questions/15771449/ipad-ios-memory-management-how-to-free-up-real-memory-used-by-uiimageviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!