ceiveMemoryWarning和viewDid卸载内存问题

ceiveMemoryWarning和viewDid卸载内存问题

本文介绍了didReceiveMemoryWarning和viewDid卸载内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了一个按钮(未在viewDidLoad中创建数据),我将填充3个NSDictionarys NSArrays,在这两种方法中还是仅一种或另一种都可以摆脱这种内存?谢谢!

I have 3 NSArrays of NSDictionarys that I populate if a button is selected (data is not created in viewDidLoad), do I get rid of this memory in both of these methods, or just one or the other? Thanks!

推荐答案

这取决于您何时需要此数据.

It depends on when you need this data.

  • dealloc 中,您应释放所有保留的ivars.
  • viewDidUnload 中,您应释放在 viewDidLoad 中重新创建的所有ivars.
    • 例如,您可能会发布一个NSDictionary映射到UIButton的ID,因为无论如何这些ID都会在 viewDidLoad 中重新创建,但要保留一个NSDictionary,用于存储选择的ID和未选择的ID.
    • In dealloc, you should release all retained ivars.
    • In viewDidUnload, you should release any ivars that are recreated in viewDidLoad.
      • For example, you might release an NSDictionary mapping ids to UIButtons, since these will be recreated in viewDidLoad anyway, but keep an NSDictionary that stores which ids are selected and which are not.
      • 例如,即使UIViewController不再可见,它也会经常保持其视图不变,直到收到 didReceiveMemoryWarning .

      这篇关于didReceiveMemoryWarning和viewDid卸载内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:06