How do you handle memory management of outlets in the iPhone SDK

允我心安 提交于 2019-12-12 09:29:06

问题


Since KVC is used to set outlets on the iPhone, there are 2 methods (that I know of) to make sure you've properly handled memory management.

Specifically, I am referring to this article written by Aaron Hillegass.

My question is which method do you use and what is your reasoning?

  • Release all your outlets in dealloc and viewDidUnload (Make sure you set them to nil in viewDidUnload.)
  • Make your outlets weak references

Personally, I am leaning towards using weak references as it seems cleaner.


回答1:


I go with weak references. As you say its less cluttered and makes an already overly verbose code foorprint a little more manageable




回答2:


Weak references are easier, yes. Clearer? A retain property as just as clear, and you can be more explicit about when something is released.

Personally I like to primarily use properties to expose some attribute of the class to the outside world - so for IBOutlets only the class will manipulate, I simply declare them without using properties and release them in dealloc.

In either case set to nil IBOutlet references in viewDidUnload.



来源:https://stackoverflow.com/questions/1386623/how-do-you-handle-memory-management-of-outlets-in-the-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!