• 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: Who should release whom in a document-based app?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Who should release whom in a document-based app?


  • Subject: Re: Who should release whom in a document-based app?
  • From: "Dennis C. De Mars" <email@hidden>
  • Date: Wed, 28 Jul 2004 10:51:46 -0700

Yes, currently in order to avoid retain cycles, you mustn't allow binding key path to go through the window controller object.

The way I get around this (which is less roundabout than the method I described the last time I posted on the subject) is to create an NSObjectController object in the nib file, and set this to point to my model objects.

Note: you CANNOT connect the content outlet of the NSObjectController to the window controller; you'll still get a retain cycle if you do that. Rather, create an outlet in your window controller and connect that to your NSObjectController.

Then, when the nib is instantiated, programatically set the content of the NSObjectController to point to your model objects. Currently I do this by leaving the default contents of the NSObjectController set to an NSMutableDictionary and inserting the model objects as values in this dictionary. The keys that you use when you add the entries are the keys you use to refer to the objects in your bindings.

If you just had one model object or one object that contains all of your model objects (like your document object) you could probably just set the content of the NSObjectController to be that object. I haven't tried that yet, but I am pretty sure it would work (the API reference for NSObjectController is really too terse, by the way...I think it needs to be expanded upon).

- Dennis D.

On Jul 27, 2004, at 8:14 PM, Allan Odgaard wrote:

On 28. Jul 2004, at 3:52, Rick Hoge wrote:

[...] I respond to windowWillClose in the window controller, and note that the retain count of both the document and the window controller are unexpectedly high (3 for the doc, 8 for the window controller). I have a number of custom views in the document nib file and these do not get the dealloc message either.

This is somewhat complicated by the fact that there are Cocoa bindings to the window controller in the nib file. [...]

And that is your problem, since the views will then retain the window controller, thus causing a cycle (since the window controller retains top-level nib objects, which retain...).

There has been some discussions about this earlier, but there is no easy fix for the problem. What I do is manually unbind all my bindings, although it's quite tedious (since you may then also need to introduce IBOutlets)...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Who should release whom in a document-based app? (From: Rick Hoge <email@hidden>)
 >Re: Who should release whom in a document-based app? (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: Right arrow keypress == enter keypress in NSTableView subclass?
  • Next by Date: Re: Where is NSList?
  • Previous by thread: Re: Who should release whom in a document-based app?
  • Next by thread: Bindings - Preserving the Modal/Controller
  • Index(es):
    • Date
    • Thread