• 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
Document object retain and release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Document object retain and release


  • Subject: Document object retain and release
  • From: Michael Dagate <email@hidden>
  • Date: Tue, 26 Jun 2001 12:13:38 -0500

Since my original post, I created very simple test app and found that using windowNibName works correctly, but using makeWindowControllers does not. Apparently, I am overlooking something basic, but I don't know what and I haven't found a good example to follow. Can anyone help me out here? Thanks.

=====================

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


  • Follow-Ups:
    • Re: Document object retain and release
      • From: "David P. Henderson" <email@hidden>
  • Prev by Date: Re: [semi-OT] ADC Sherlock Plugins
  • Next by Date: warning: xxx.app depends on itself
  • Previous by thread: Document object retain and release
  • Next by thread: Re: Document object retain and release
  • Index(es):
    • Date
    • Thread