On Aug 9, 2011, at 05:24 , Shane Stanley wrote:

> I have a document-based application that uses garbage collection. It's 
> straight-forward in terms of having subclasses of NSDocument, NSWindow, and 
> NSWindowController, and documents have a single window (with drawer, if that 
> makes any difference).
> 
> But when I close a window/document, the window gets orderedOut, so it never 
> closes. I can, for example, use the scripting interface after a document has 
> been closed and make its window visible again.
> 
> When I close I see performClose: being called, windowShouldClose: being 
> called on the delegate (the window controller), then close on the window, 
> followed by windowWillClose: on the delegate, and then orderOut on the window.

It's not entirely clear what it is you're expecting here.

AFAICT -- and I have spent some time pondering the documentation and APIs on 
this -- there really *isn't* anything that you could call "closing a window" 
other than the sequence you describe above. Again AFAICT, window closing and 
ordering-out are indistinguishable, for all practical purposes at least.

The only difference that might happen at close time, which you'd normally want 
for a document window, is that the window might get released. (In GC terms, 
there might be no strong references and so the NIB objects can get garbage 
collected.) That's where things can get a little murky, because there are 
sometimes unexpected strong references.

The most obvious cause of this kind of lingering is the NIB mechanism itself. 
Normally, top level objects in a NIB receive an extra retain when loaded (have 
an extra strong reference, in the GC case). For windows specifically, there is 
a checkbox in IB that says "release when closed". For a document window, you 
should check this box so that (presumably) when the window is closed the extra 
strong reference is discarded.

I suspect this is the cause of your window's lingering. If that's not it, then 
use the debugger's 'info gc-roots' command (having set a breakpoint somewhere 
after the window has been closed and the collector has had time to run, 
preferably) to find out what's keeping the window 
alive._______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to