views:

137

answers:

2

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  A: 

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

ennuikiller
+1 I also use (nonatomic, assign) for all my outlets. Then I don't have to remember to do anything.
Dave DeLong
But as the article states, you have to make sure the view is loaded when you use this technique - or you can encounter random crashes accessing IBOutlets after the view unloads.
Kendall Helmstetter Gelner
+1  A: 

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.

Kendall Helmstetter Gelner