Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad iOS memory management - how to free up "Real Memory" used by 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.

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:

enter image description here

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

enter image description here

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: enter image description here

like image 403
Alex Stone Avatar asked Apr 02 '13 18:04

Alex Stone


1 Answers

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.

like image 127
Alex Stone Avatar answered Nov 08 '22 23:11

Alex Stone