问题
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