2

I'm new to developing for iOS. I've seen a lot of documentation about controlling memory management programmatically, however I'm curious about the default way iOS handles memory when navigating between:

  • Tabs
  • Master-Detail Views
  • Master-Detail Views with Tabs

(Note: When I say a Master-Detail view, I am basically referring to a Navigation Controller. I'm just calling it a "Master-Detail View" to define two different levels of the Navigation Controller hierarchy, so its easier for us to discuss)

I will go through each of the 3 topics with the questions I have:

Tabs

  1. When the app first boots up, does it load all of the data into RAM for each of the tabs, or does it just load the data for the tab that is initially displayed?
  2. If the answer to 1 is no: Whenever you switch from one tab to another, does it deallocate the data of the tab you switched from?
  3. If the answer to 1 is yes: If the app needs to load data from a database in each of its tabs: does it just load the user interface / local functionality into RAM, and only load from the database data when that tab is selected (when this data is needed)?

Master-Detail view (in the case where the Master is a UITableViewController, and the Detail is just a UIViewController and they are embedded in a Navigation Controller)

  1. When you load a Detail View, then go back to the Master View, does the data from the Detail view still remain in RAM?
  2. When you load a Detail View, then go back to the Master View, then go into a different Detail view, does the first Detail view's data stay in RAM?

Master-Detail Views with Tabs (in the case where the Master is a UITableViewController, and the Detail is just a UIViewController and they are embedded in a Navigation Controller)

  1. When you load a Detail View, then switch to a different tab, is the Detail View's data still in the RAM?
  2. When you load a Detail View, then go back to its Master View, then switch tabs, is the data from the Detail View still in RAM?

All of these questions are referring to the default behavior of iOS.

4

2 回答 2

2

几个想法:

  1. 诊断:诊断正在发生的事情的最简单方法是将日志记录语句添加到您的子视图控制器。例如,如果您在viewDidLoadanddealloc方法中添加以下行,您将被通知为控制器并加载和释放:

    NSLog(@"%s", __FUNCTION__);
    

    然后,配备将在实例化和释放时记录的视图控制器,您可以在容器控制器(标签栏控制器、导航控制器、拆分视图控制器等)的任何组合中使用这些控制器,并且您可以轻松查看发生了什么你自己。

  2. 关于您询问的特定容器控制器:

    • 标签栏控制器:在故事板中,标签栏控制器在您选择它们​​各自的标签(而不是之前)时分配子控制器,但保留旧标签。(在 NIB 中,这仅取决于您以编程方式执行的操作;您可以预加载它们,也可以不预加载它们。)

    • 导航控制器:当您推送到特定场景时,导航控制器会加载新的子控制器,但它不会在该过程中释放先前的视图控制器。只有当您从导航堆栈中弹出视图控制器时,该控制器才会被释放。

    • 拆分视图控制器:当您在拆分视图控制器中执行替换转场时,它将实例化新的子场景,并释放之前的子控制器。如果之前的子控制器本身是一个容器控制器,例如选项卡或导航控制器,那么它的子控制器也会被释放。

于 2013-07-12T18:16:31.830 回答
0

如果您真的想知道,请使用 Instruments 来查看内存。您可以确切地看到分配事物的时间以及修改保留计数的时间以及修改的内容。通常我不在乎,除非我的应用程序在开发过程中收到内存警告,或者我怀疑有泄漏(ARC 有时仍然会发生这种情况)。顺便说一句,如果你不是,你应该使用 ARC。

于 2013-07-12T19:16:18.793 回答