Quote:
Originally Posted by ozzie
So I have several viewControllers, each creates images using "imageWithContentsOfFile" in order to conserve memory and then sets objects to nil and releases them in the dealloc method. The imageViews are blank but are created in interface builder with the images added programmatically using imageWithContentsOfFile when needed. There are no memory leaks. The problem is memory still builds up when switching views. So for example I'll be in view1 and it'll be using 8MB of memory and then I'll switch to view2 and back to view1 again and it'll be now using 10MB of memory. I've checked allocations in instruments and it's the images using it. Is there something I need to do to flush the memory out or something?
Thanks in advance!
|
View controllers are not normally unloaded/deallocated. They stay in memory, and their views get released if they are not the front view controller and the device issues a low memory warning.
The view controllers themselves are not usually released/deallocated at all. They usually persist for the life of the app. You're supposed to set them up so that large data structures are created in viewDidLoad, and discarded in viewDidUnload (if you can reconstruct them.) The view controllers themselves are fairly light weight. It's their view hierarchies and data models that take up the most memory.
This approach gives you fast loading of views for most-used forms, and lets the system free memory when it really needs to.