views:

131

answers:

2

In the Memory Management Programming Guide for Cocoa Apple talks about Top-Level Objects. They say, that I need an Outlet for each of them.

If there are any top-level objects you do not store in outlets, however, you must retain either the array returned by the loadNibNamed:owner:options: method or the objects inside the array to prevent those objects from being released prematurely.

So what exactly do they mean with "top-level object"? I would say they talk about the root view and window. What else? And is this hint just for cases in which I would want to load their nib manually? Or does it apply for any nib and any case?

+3  A: 

Yes, this is about the cases where you load the Nib manually, else you wouldn't have called loadNibNamed:owner:options:.

foljs
IIRC that's true for the Mac, but for UIKit, you have to retain all top level objects apart from the -view in a UIViewController as well, or it'll get autoreleased after loading. Or am I misremembering the differences here?
uliwitness
+5  A: 

Top-level objects are objects that appear in the main nib window in Interface Builder, other than File’s Owner and Application.

Ahruman
Actually, on MacOS at least, the application is a top-level object as well. The NSTopLevelObjects array returned by loadNibNamed:owner:options:, for some odd reason, also includes NSApplication.
uliwitness