Hi,

Here is the result from gc-roots for a window controller that was not collected:

(gdb) info gc-roots 0x1048c10
Number of roots: 1
Root:
0 Kind: stack rc: 0 Address: 0xbfffee24 Frame level: 3 Symbol: <unknown> 1 Kind: object rc: 0 Address: 0x01047be0 Class: NSWindow ivar: NSResponder 2 Kind: object rc: 0 Address: 0x01048c10 Class: MyWindowController

(gdb) info gc-references 0x1048c10
0 Kind: object rc: 0 Address: 0x01047be0 Class: NSWindow ivar: NSResponder 1 Kind: object rc: 0 Address: 0x01047be0 Class: NSWindow ivar: NSResponder 2 Kind: object rc: 0 Address: 0x01047be0 Class: NSWindow Offset: 0x0000001c 3 Kind: object rc: 0 Address: 0x01048c10 Class: MyWindowController ivar: NSWindowController warning: can't find class named `NSWindowAuxiliary' given by ObjC class object 4 Kind: object rc: 0 Address: 0x01066eb0 Offset: 0x0000002c Class: NSWindowAuxiliary warning: can't find class named `NSButtonCell' given by ObjC class object 5 Kind: object rc: 0 Address: 0x0106f9f0 Offset: 0x00000018 Class: NSButtonCell

Should I understand that some unknown object keeps a reference to the window, which keeps a reference to my window controller?
Unfortunately, I am not sure of how to interpret that result.

Thanks!

Mathieu

On 27-Nov-08, at 6:18 PM, Bill Bumgarner wrote:

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/mcoursolle%40rogue-research.com

This email sent to [EMAIL PROTECTED]


_______________________________________________

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