removeFromSuperview, _registerDragTypesLater, and clean exits
removeFromSuperview, _registerDragTypesLater, and clean exits
- Subject: removeFromSuperview, _registerDragTypesLater, and clean exits
- From: Geoff Schmidt <email@hidden>
- Date: Thu, 22 May 2008 17:27:16 -0700
Summary: A surprising property of removeFromSuperview prevents my
application from fully freeing a nib. Any suggestions?
--
I wanted to be sure my nibs were getting unloaded correctly, so I
turned to ObjectAlloc. I found that one of my nib-loaded NSWindows
and all of its views, table columns, etc, were still hanging around
with nonzero reference counts after my application had exited.
The surprising culprit was removeFromSuperview, which I call while
handling applicationWillTerminate. (I have a window with swappable
views that are loaded from nibs and removeFromSuperview is called as
part of its teardown.) removeFromSuperview calls retain twice on the
window that is losing the view, but only calls release once, and does
not call autorelease. This leaves a reference to the NSWindow that
prevents it from being deallocated before the process exits.
So what's the source of this reference? It appears that
removeFromSuperview calls a function called _registerDragTypesLater
on the losing window, which in turn calls
performSelector:withObject:afterDelay: to schedule a function
_registerDragTypes to be called 1 ms later (afterDelay = .001), which
accounts for the reference. This appears to be part of a strategy to
perform _registerDragTypes only once even when lots of changes are
made to a window's view hierarchy.
However _registerDragTypes is never called and so the reference is
never released, because the run loop exits after calling
applicationWillTerminate. In fact, calls scheduled with
performSelectorOnMainThread:withObject:waitUntilDone: from
applicationWillTerminate aren't called either.
I would like this nib to unload cleanly, because that means that I
can look in ObjectAlloc and see that all of the NSWindows and NSViews
got dealloc'd and feel confident that all of my nib unloading logic
is correct. Any suggestions?
* Is it possible to make removeFromSuperview not schedule the call to
_registerDragTypes?
* Is it possible to delay the exit of the main run loop for a small
amount of time, like 10ms, so that performSelector calls made from
applicationWillTerminate have a chance to complete?
* Is clean shutdown (at least with respect to NSWindow/NSView) just a
lost cause? :)
thanks,
Geoff
_______________________________________________
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