FROM : Michael Babin
DATE : Thu May 15 17:59:15 2008
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.
DATE : Thu May 15 17:59:15 2008
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.
| Related mails | Author | Date |
|---|---|---|
| André Pang | May 15, 09:21 | |
| Ken Thomases | May 15, 10:36 | |
| Chris Suter | May 15, 14:09 | |
| André Pang | May 15, 16:53 | |
| Michael Babin | May 15, 17:59 |






Cocoa mail archive

