• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Proper Way to "Unload" a Loaded Nib w/Bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Proper Way to "Unload" a Loaded Nib w/Bindings
  • From: Guy English <email@hidden>
  • Date: Tue, 27 Mar 2007 19:02:16 -0400

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:
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:
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>)

  • Prev by Date: Re: Proper Way to "Unload" a Loaded Nib w/Bindings [Solved, Maybe]
  • Next by Date: Re: FSPathFileOperationStatusProcPtr callback error: -8081
  • Previous by thread: Re: Proper Way to "Unload" a Loaded Nib w/Bindings
  • Next by thread: Core data store's as a document file format
  • Index(es):
    • Date
    • Thread