Closing vs quitting documents
Closing vs quitting documents
- Subject: Closing vs quitting documents
- From: Serge Meynard <email@hidden>
- Date: Tue, 29 Mar 2005 08:49:10 -0500
Greetings,
this type of question has been asked a few times before on the list,
but the problem was never quite the same, so here goes again.
My app is document-based. The main window contains (among others) a
custom view, which is my "main" data view. I can also open secondary
windows, which also contain an instance of this custom view. The views
each create an overlay window, and release it when they get
deallocated.
Everything works as intended, but I get a crash if I quit the app with
a document and a secondary window open. If only the main window is
open, or if I close the document first, the app quits fine. After much
hair-pulling and tracing of events, I found that the problem is indeed
the overlay window (the problem vanishes if I don't create it). I also
discovered that it's apparently the framework doing something naughty
(although I loathe to claim such a thing, that's what it looks like).
Here's a list of the events I observe for each case:
Closing a document (main window)
* main view gets dealloc call from autorelease pool, overlay window
is released, no crash
Closing a document (main window + secondary)
* main view gets dealloc call from autorelease pool, overlay window
is released, no crash
* secondary view gets dealloc call from autorelease pool, overlay
window is released, no crash
Quitting (main window)
* [NSApp terminate] calls _deallocHardcore
* _deallocHardcore calls close on the overlay window, which
autoreleases it
* _deallocHardcore calls [NSAutoreleasePool releaseAllPools], which
deallocates the overlay (!?)
* main view DOES NOT get a dealloc call, so no crash
Quitting (main window + secondary)
* [NSApp terminate] calls _deallocHardcore
* _deallocHardcore calls close on both overlay windows, which
autoreleases them
* _deallocHardcore calls [NSAutoreleasePool releaseAllPools], which
deallocates both overlays (!?)
* main view DOES get a dealloc call, which releases the overlay and
crashes
So it looks like 1) Cocoa is deallocating something it shouldn't be (I
still have a retain on the overlays in the custom views) and 2) the
only reason it doesn't crash all the time when I quit is because my
view is not consistently being deallocated.
Can someone provide a better understanding of what's going on when I
quit? Why are the overlay windows being released one too many times by
the framework? Why is dealloc not being called systematically? I can
imagine ways of working around this, by moving the code out of the
dealloc and checking if the app is quitting or not, but I would hate to
go there without even knowing what the cause is. Any help would be
appreciated.
Serge
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden