views:

105

answers:

1

Apple says, that I need to have Outlets in my File's Owner for all my top level objects in a Nib file.

As much as I know, these objects are NOT the File's Owner itself (would make no sense, right?) and the First Responder.

I am unsure about: The View object in the Nib, and any controller object in the nib. Do I need an outlet for those in File's Owner?

This question is regarding memory management. They say:

You should always keep a pointer to these objects somewhere because your application is responsible for releasing them wen it is through using them

So when the user closes the app, I would have a clunky memory leak if I'd miss those outlets?

+2  A: 

That's correct. The File's Owner for a Nib file is the entry point into that nib. Since nothing outside your nib can refer to anything but the File's Owner, only the File's Owner can refer to other top-level items in the nib. If the File's Owner doesn't refer to them, then there is no way to release those objects when the nib is no longer needed, and they will hang around in memory.

The life cycle of a nib is something like this:

  1. The nib is loaded and the File's Owner is associated with an object you specified.
  2. Memory is allocated for all the top-level objects in the nib.
  3. All the outlets are hooked up as specified in the nib.
  4. ... stuff happens ...
  5. The File's Owner object is sent a release message.
  6. The File's Owner releases all the objects hooked up to its outlets.

As you can see, any object that was allocated in the second step will still be floating around in memory if it wasn't released in the final step.

Tony