[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWindowController, Nibs & Object ownership



Alas, I'm not using NSDocument, so I don't know if this has 
helped much....
>


> It is only one of the great mysteries of Cocoa because Apple 
> was trying to
> be a little bit too clever IMHO.
> If you ever write your own document management classes, you 
> will see that
> nothing mysterious is happening.  All of the features of 
> NSWindowController,
> NSDocument, and NSDocumentController are (or could be) 
> implemented using
> existing delegate methods of NSWindow and NSApplication.
>
> To answer your question: An NSDocument subclass "owns" one or more
> NSWindowController instances.
> An NSWindowController instance "owns" all of the top level 
> objects in the
> nib that it loaded.
>
> All you have to do is release an instance of a subclass of 
> NSDocument and it
> will automatically release all of its window controllers and 
> they in tern
> release all of the top level objects loaded from a nib.
>
> All you have to do is decide under what circumstances you are ready to
> release an instance of a subclass of NSDocument and release 
> it.  You may not
> even need to do this because when a document closes it removes 
> itself from
> the document controller and the document controller releases 
> the document.
>
> If everything is configured correctly as it is by default, 
> document closure
> cleans up everything.  If that is not happening, check for 
> places in your
> code that retain documents or model objects.
>
>
>
>
>

--
Dan Wood
Karelia Software, LLC
dwood@xxxxxxxxxxx
http://www.karelia.com/
Watson for Mac OS X: http://www.karelia.com/watson/