• 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
Re: Garbage collection leak in simple Core Data application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage collection leak in simple Core Data application


  • Subject: Re: Garbage collection leak in simple Core Data application
  • From: Mathieu Coursolle <email@hidden>
  • Date: Fri, 28 Nov 2008 08:49:36 -0500

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 (email@hidden)

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:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Garbage collection leak in simple Core Data application
      • From: Bill Bumgarner <email@hidden>
References: 
 >Garbage collection leak in simple Core Data application (From: Mathieu Coursolle <email@hidden>)
 >Re: Garbage collection leak in simple Core Data application (From: Rob Keniger <email@hidden>)
 >Re: Garbage collection leak in simple Core Data application (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: -[NSWindowController window] fails
  • Next by Date: ... not sure if this is a KVO or a Core Audio problem with my code
  • Previous by thread: Re: Garbage collection leak in simple Core Data application
  • Next by thread: Re: Garbage collection leak in simple Core Data application
  • Index(es):
    • Date
    • Thread