ImageIO dirty memory is not automatically cleared by iOS

Putting this here as too big for a comment, just some ideas:

1) one way to retain objects by mistake is to have objects in views that get hidden but not removed from their superview (and thus stay retained)

2) if you do anything with UIImageView etc on any thread not the main thread bad things can happen (like this)

3) copy your project so you can freely mess with it, and try a bunch of things:

  • instead of multiple images, always load the same image, but leave the other parts of your code as they are - do things change?

  • In any subclasses you create that would hold/retain images, put a log message in the dealloc to see if in fact those objects are getting dealloced.

  • subclass UIImageView, use it for the images, and log the dealloc

  • subclass UIImage, use it for these images, log the dealloc

4) I am having a hard time believing imageio has a defect that would do this, but what you could do is switch to using imageWithData, and load the data yourself. Use the F_NOCACHE flag when you actually read the data - there is other code on SO on how to do this, you can search on it (I answered a question on it).

If you can create a demo project with this defect, it would be a lot easier to debug it than just guess at what to do. Logging the class that gets dealloc'd goes a long way, since you will see immediately what is not getting released, and then better focus in on the problem.


In addition to David H's answer I would recommend anyone who's experiencing this problem to also check if your View Controller's, Model's, UIDocument's (if you use it) deinitializers are called when not needed.

If you don't properly deallocate these classes and they contain the image / VDO / content data that UIKit refers to it, then this may result in this scenario where you see VM: ImageIO memory usage always increasing, and yet you see no memory leak when you use Instruments since these contents are now retained internally by UIKit.

I experienced this very issue too, twice, and in my case it turned out that my Model's deinitializer was never called due to unrelated issues. By fixing those unrelated issues and making sure my Model is deallocated, these VM: ImageIO continuous growth disappeared.

enter image description here