On Nov 28, 2008, at 8:42 AM, Rob Keniger wrote:
You are adding the NSWindowController to your document using - addWindowController:, which retains the window controller. You must then release the window controller using -removeWindowController: so that the collector frees the object.

Do this in MyDocument.h:

#import <Cocoa/Cocoa.h>
@class MyWindowController;
@interface MyDocument : NSPersistentDocument {
        MyWindowController* newWindowController;
}
@end

and change these methods in MyDocument.m:

- (void)makeWindowControllers
{       
        // Create the project window controller and keep a reference to it.
        newWindowController = [[MyWindowController alloc] init];
        [newWindowController setShouldCloseDocument:YES];
        
        // Add it to the list of window controllers for this document.
        [self addWindowController:newWindowController];
}

- (void)finalize
{
        [self removeWindowController:newWindowController];
        NSLog(@"Document finalized");
        UpdateDocumentCount(0);
        [super finalize];
}


That shouldn't be necessary unless the document is also sticking around. The collector handles disconnected cyclic sub graphs just fine; there is no such thing as a retain cycle under GC.

What is rooting the window controller?

I.e. if you can grab the address of the window controller, then break in gdb and 'info gc-roots <address>'. It should tell you why the window controller hasn't been reaped.

Or you can use the Object Graph instrument in the Instruments application.

b.bum

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to