Re: Beginner Questions
Re: Beginner Questions
- Subject: Re: Beginner Questions
- From: James Spencer <email@hidden>
- Date: Wed, 2 Feb 2005 20:03:04 -0600
On Feb 2, 2005, at 2:18 AM, j o a r wrote:
On 2005-02-02, at 03.58, James Spencer wrote:
I'm having trouble understanding how dellocation of objects
instantiated in nib files is handled. The question arises in
connection with my first Cocoa application utilizing bindings.
I have a simple document based application. The nib for the document
contains, in addition to the main window for the document, a custom
NSArrayController. The nib file's owner is the document. I have
noted that when the main window is closed, the document is being
closed and deallocated. What has me confused is that my custom
NSArrayController is NOT being deallocated. Now, obviously I can
release the controller from my document's dealloc method or I can
watch for the window's notification of it's intent to close and have
the controller release itself when it gets notified but I had thought
that in a document based application, all top level objects in the
nib (which in this case includes my array controller) would be
released when the document got released.
Can anyone give me the quick nickel tour of what get's closed when a
window, which was loaded with the rest of a nib by the document, is
closed?
If the owner of your nib file (owner = the object that loads the nib
file, the object that has the outlets that you've connected in your
nib file) is a subclass of NSWindowController, memory management for
the objects loaded from the nib file will be handled automatically for
you.
The documentation for this functionality can be found here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/
Concepts/WinControllersAndNibs.html>
If you on the other hand load a nib file in any other way, you are
responsible for releasing all "top level" objects in the nib file at
the appropriate time. The "top level" objects are all objects you find
in the nib file window in IB, not including the "proxy" objects -
files owner, first responder, et.c.
Thank you. This makes sense. I had read this article but was being
stupid and was not understanding what it was implying for situations
where the window controller was the nib file's owner. This makes
perfect sense.
How do you verify that the array controller is not deallocated? Note
that it might be autoreleased, and in that case deallocation would
typically happen at the end of the current event loop and perhaps not
exactly when the document is deallocated.
A break point on dealloc did not appear to be firing. Having said
that, I cannot recreate the problem and solved my immediate problem
(removing the array controller as an observer of a user default) by
watching for the window's notification that it is about to close and
removing the observer then rather than during the controller's dealloc
method.
Thank you again.
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden