Document object retain and release
Document object retain and release
- Subject: Document object retain and release
- From: Michael Dagate <email@hidden>
- Date: Fri, 22 Jun 2001 14:57:39 -0500
Hi,
I'm having a problem with my document-based Cocoa app. The document
object (a subclass of NSDocument) and the window controller object (a
subclass of NSWindowController) never get fully released and dealloc'ed
by the document controller object (the shared NSDocumentController
object provided by Cocoa). As a result, other objects don't get released
and dealloc'ed either.
I checked the "Release when closed" option in the nib file, but this
hasn't helped. I create documents programmatically using the following
statement:
[[NSDocumentController sharedDocumentController]
openUntitledDocumentOfType:@"MainDocument" display:YES];
In the document class, I use makeWindowControllers to create the window
controller object. In the window controller class, the windowDidLoad
method gets called, as expected; however, in the document class, the
windowControllerDidLoadNib method does not. Here is the code I use to
load the nib:
- (id)init
{
if (self = [super initWithWindowNibName:@"MainWindow"])
{
NSLog(@"MainWindow init");
[self setShouldCloseDocument:YES];
}
return self;
}
Document windows do open and close upon request, and the Window menu
contains the names of the open document windows. Curiously, new windows
don't cascade, they appear on top of each other (I don't know if that is
a subtle clue or not).
I thought that the NSDocumentController object would retain and release
document objects and window controllers as needed, but i must be missing
something. I overrode retain and release to print the retainCount for
each object and found that the retainCount never goes to zero - it stops
at one.
Any idears?
Many thanks,
Michael