Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper Way to "Unload" a Loaded Nib w/Bindings



Sorry I should make that clear - NSWindowController works perfectly with what you're doing.

If your File's Owner is not an NSWindowController (or subclass) and you expect to be able to unload the view (and not leak) then you need to take steps to make it work correctly.

NSWindowController has some magic in it that tracks and breaks the retain cycles. The original poster said: "I would just use an NSWindowController but I need to display windows in various modal forms, such as sheets and regular modal windows." so I believe he's running into the retain cycle problem.

On 27-Mar-07, at 5:42 PM, R. Matthew Emerson wrote:


On Mar 27, 2007, at 4:29 PM, Guy English wrote:

There is insanity involved when you bind to the File's Owner. And by insanity I mean some nasty retain cycles can get created. See the thing is when you instantiate the nib you get a retain on it and when objects inside the nib bind to you they retain you. You don't know (normally) what has been bound to you so digging your self out of the hole is a pain.

The easiest solution is put a controller class in the nib and bind to that. Have an outlet from your File's Owner to this controller class instance. If you look at NSWindowController you'll see there's mechanisms in there to handle the autounbinding correctly. Ultimately it'd be great to get an NSViewController to do the same in the (increasingly common) circumstance.

I have been binding via File's Owner frequently. I have a document- based application with multiple windows per document. Each window has its own nib, and the File's Owner in each nib is an NSWindowController subclass. Typically, NSController instances in the nib bind to the document's managed object context and to model objects therein via the File's Owner (i.e., the window controller).


A typical key path would be something like "document.thing.widgets".

Should I not be doing this?  If not, how should I have known better?

(I'll be glad when we have garbage collection and can quit worrying about retain cycles.)



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/guy.english% 40gmail.com


This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Proper Way to "Unload" a Loaded Nib w/Bindings (From: Keary Suska <email@hidden>)
 >Re: Proper Way to "Unload" a Loaded Nib w/Bindings (From: "Shawn Erickson" <email@hidden>)
 >Re: Proper Way to "Unload" a Loaded Nib w/Bindings (From: Guy English <email@hidden>)
 >Re: Proper Way to "Unload" a Loaded Nib w/Bindings (From: "R. Matthew Emerson" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.