Re: Window close
Re: Window close
- Subject: Re: Window close
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 03 Oct 2002 16:45:51 -0400
on 02-10-03 1:08 PM, Edward Fink at email@hidden wrote:
>
so I do a [self release] within the
>
"windowWillClose". This works perfectly for me when I use <command-w>.
>
However, if I actually "click on the X" to close the window...the
>
app crashes. Now to fix this I have changed [self release] to [self
>
autorelease]. That fixes my problem....however I do not understand why?
You're releasing the window too soon. The windowWillClose delegate method is
triggered BEFORE the window actually closes (that's why it says "Will" --
future tense). So if you force it to deallocate itself at that point, Cocoa
may still do something that expects the window object to be in existence,
and things go wrong if it isn't. Apparently, the Command-W operation doesn't
cause Cocoa to try to do anything with the window object, while clicking on
the close button does (highlighting the button momentarily, perhaps?), so in
the latter case the app crashes when it finds that the window object is
gone.
Autorelease works because autorelease postpones the release and the
resulting dealloc until the next time around the event loop, and apparently
that's enough leeway to let Cocoa wind things down OK.
Now, windows in Cocoa normally move themselves offscreen and remain in
existence when they're closed, as I understand it, so that they can be
reopened faster. So you probably shouldn't be releasing the window at all.
If you really do have some good reason to release your window when it's
closed, there is an Interface Builder option to do this (the "Release when
closed" checkbox in the NSWindow Info Panel).
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: | |
| >Window close (From: Edward Fink <email@hidden>) |