• 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: Bill Bumgarner <email@hidden>
  • Date: Thu, 27 Nov 2008 15:18:35 -0800

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


  • Follow-Ups:
    • Re: Garbage collection leak in simple Core Data application
      • From: Mathieu Coursolle <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>)

  • Prev by Date: Re: Garbage collection leak in simple Core Data application
  • Next by Date: Re: What is the best way to get an NSSlider to respond to the mouse scroll wheel?
  • 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