Re: Crash when MyDocument becomes the delegate of NSApplication
Re: Crash when MyDocument becomes the delegate of NSApplication
- Subject: Re: Crash when MyDocument becomes the delegate of NSApplication
- From: Jochen Moeller <email@hidden>
- Date: Sat, 25 Jul 2009 04:24:34 +0200
Hi Kyle,
You are right, I did not consider that.
Because NSDocument is a controller object I used it similar to a self-
made AppController.
Thanks for your explanation.
Jochen Moeller
Am 25.07.2009 um 03:26 schrieb Kyle Sluder:
Why would your document be an NSApplication delegate? What happens
when you have two documents open -- you can't have two NSApplication
delegates. So your short solution is: "stop making your documents the
delegate of your application."
The reason why you were getting a crash:
NSApplication lives for the duration of your application (duh.) It
does not retain its delegate, because delegates are not retained
according to Cocoa memory management rules (this is because they often
retain the thing they're a delegate of). So when you create a
document and set it to be the app's delegate, and then close the
document, the application is still going to send its delegate messages
to whatever pointer it remembers as its delegate. Unless you
explicitly say [NSApp setDelegate:nil] in your document's -dealloc
implementation, NSApplication is going to have a weak pointer to
nowhere, and will crash when sending a message to it.
--Kyle Sluder
_______________________________________________
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