IBOutlet and viewDidUnload under ARC IBOutlet and viewDidUnload under ARC ios ios

IBOutlet and viewDidUnload under ARC


Just doing a bit of research...

As I understand it, weak is similar to assign, in that they're both weak references.

However, assign does not create a zeroing reference. i.e. if the object in question is destroyed, and you access that property, you WILL get a BAD_ACCESS_EXCEPTION.

Weak properties are automatically zeroed (= nil) when the object it is referencing is destroyed.

In both cases, it is not necessary to set property to nil, as it does not contribute to the retain count of the object in question. It is necessary when using retain properties.

Apparently, ARC also introduces a new "strong" property, which is the same as "retain"?

Research done here


I did a little testing and it appears that the code in the viewDidUnload method is unnecessary. To support this, the docs for viewDidUnload do actually say:

By the time this method is called, the view property is nil.

Indicating that the weak reference must have been set to nil automatically.


I have some empirical evidence to support that IBOutlets are indeed already set to nil automatically. Here's what I did:

  1. I set up explicit ivars for my IBOutlet properties (@synthesize myLabel = myLabel_) so that I may later inspect their values in the debugger.
  2. I enabled a breakpoint on the first line of viewDidUnload.
  3. I arranged for viewDidUnload to get called by simulating a memory warning.
  4. I inspected the values of the explicit ivars that I associated with my IBOutlet properties.

The explicit ivars all had nil as their value then I hit the breakpoint.