tabbar memory management

前端 未结 3 1089
误落风尘
误落风尘 2021-01-16 07:22

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

相关标签:
3条回答
  • 2021-01-16 07:57

    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.

    0 讨论(0)
  • 2021-01-16 07:58

    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.

    0 讨论(0)
  • 2021-01-16 08:13

    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:

    1. You start on tab 1. Tab 1 is the only view controller whose view will be loaded.

    2. You tap on tab 2. Now tab 2's view controller will be loaded and tab 1's view controller is still around.

    3. More time goes on, you tap on other tabs which loads other view controllers.

    4. 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.

    0 讨论(0)
提交回复
热议问题