What “top-level objects” are Apple referred to in the Memory Management Programming Guide?

In Cocoa's Memory Management Programming Guide, Apple talks about top-level objects. They say that I need a way out for each of them.

If there are top-level objects, you do not store them in retail outlets, however, you must save either the array returned using the loadNibNamed: owner: options: method or the objects inside the array so that these objects are not released prematurely.

So what exactly do they mean by “top-level object”? I would say that they are talking about the root view and the window. What else? And is this a hint only for cases where I would like to manually download them? Or is this applicable for any nib and any occasion?

+6
iphone uikit xib nib
source share
3 answers

Top-level objects are objects that are displayed in the main window of the window in the interface designer, other than the owner of the files and application.

+6
source share

Yes, this applies to cases when you load Nib manually, otherwise you would not call loadNibNamed: owner: options:.

+3
source share

The objects that appear in the window with the file owner, the first responder, represent top-level objects. Everything that you add to the view will be subordinate - all sub-items are saved by direct control, so they do not need to be stored elsewhere. The view itself is saved by the view controller, so it does not need to be saved.

If you add non-display objects or views that you don’t place directly in your main view (for example, toolbar buttons that are not currently displayed), you need to save them or they will be released. My preferred method for this is with IBOutlets using @property, for example:

@property(nonatomic, retain) IBOutlet UIBarButtonItem * myButton; 

This calls -setMyButton: to call the owner of the file (if this code belongs to the file), and the object connected via IB is sent to save in this property.

0
source share

All Articles