a tab bar based app with 5 tabs switching option...how i am suppose to manage memory efficiently?
switching between tab are very frequent i am how to manage this sce
All View Controllers associated with a Tab Bar Controller are retained by the tab bar controller, but if you're using intense amounts of memory, you can release objects or resources used by your view controller when viewWillDisappear: or viewDidDisappear: gets called. And recreate / reallocate those memory hogging objects when viewWillAppear: or viewDidAppear: get called when the user clicks it into view again.
You don't need to worry about it, unless you're in a low memory situation, in which case the view controllers' views may be released, and you just need to correctly implement:
didReceiveMemoryWarning
and
viewDidUnload
See Apple docs here and here for details.
Let UIKit handle it. You shouldn't worry. UIKit will unload views as it sees fit (and you get told about that in viewDidUnload
of your view controllers).
So for instance:
You start on tab 1. Tab 1 is the only view controller whose view will be loaded.
You tap on tab 2. Now tab 2's view controller will be loaded and tab 1's view controller is still around.
More time goes on, you tap on other tabs which loads other view controllers.
UIKit notices that memory is running a bit low or it just wants a bit of a tidy up (you have no control over this). So now it will go and unload some of the view controllers' views (but obviously never the one you're currently viewing).
You should of course be a good citizen and release anything you hold onto in your view controller in viewDidUnload
that you can easily create again when the view wants to be loaded again.