• 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: Setting NSObjectController's to file's owner
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting NSObjectController's to file's owner


  • Subject: Re: Setting NSObjectController's to file's owner
  • From: Michael Babin <email@hidden>
  • Date: Thu, 15 May 2008 10:59:15 -0500


On May 15, 2008, at 9:53 AM, André Pang wrote:

Hmm, I just created a small test application to try to reproduce this problem and couldn't get the retain cycle to happen. It's a dead-simple document-based Cocoa application with a single NSObjectController in the nib file, with a single text field binding that was bound through the object controller to an ivar in the file's owner.

However, now the weird thing is that I call -[objectController release] in the file's owner -dealloc (which I guess should be the correct behaviour, since the object controller is declared as an IBOutlet and is a top-level nib file object), I get into an infinite "release cycle" loop. Test program here, for those willing to lend a hand:

 http://algorithm.com.au/tmp/NSObjectControllerRetainCycleTest.zip

Am I completely misunderstanding memory management of bindings/nib files objects?

In the small test application, you added the NSObjectController to the document's nib file (MyDocument.xib). As MyDocument is a descendant of NSDocument and you did not override -[NSDocument makeWindowControllers], the default implementation creates an NSWindowController with the windowNibName and MyDocument as the file's owner.


<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocument_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDocument/makeWindowControllers >

Since the created NSWindowController actually loads the nib, it is responsible for (and performs) freeing all top-level objects in the nib file. Doing so yourself in MyDocument's dealloc method is unnecessary and leads to an over-release problem, as you have discovered.

See: <http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSWindowController >, Overview.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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: 
 >Setting NSObjectController's to file's owner (From: André Pang <email@hidden>)
 >Re: Setting NSObjectController's to file's owner (From: André Pang <email@hidden>)

  • Prev by Date: Password entry dialog
  • Next by Date: Re: Guidance for Cocoa's steep learning curve
  • Previous by thread: Re: Setting NSObjectController's to file's owner
  • Next by thread: glass effect - CG call to do this?
  • Index(es):
    • Date
    • Thread