重用 UIViewController 的最佳实践是什么?在许多应用程序中(包括Apple自己的示例:例如SQLiteBooks),每次将UIViewController推送到堆栈时都会分配并初始化UIViewController。这会增加每个新 Controller 的内存使用量,因为对象保留在内存中并且不会再次使用。
如何让它变得更好?
最佳答案
This increases the use of memory with every new controller, because the objects stays in the memory and aren't used again.
只要你没有其他东西持有它,它就应该在堆栈被弹出时被释放。检查您的 dealloc 方法是否被调用。
此外,如果它被插入堆栈,那么您需要至少保留它直到它被弹出(如果您遵循标准模式,就会自动发生)。所以它被再次使用。
因此,遵循标准模式应该已经使您的内存使用量尽可能小。
关于iPhone:使用 UIViewController 以节省内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1031755/