[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

When should an NSDocument stop being an NSWindow's delegate?

From: David Chisnall
Subject: When should an NSDocument stop being an NSWindow's delegate?
Date: Sun, 25 Oct 2009 17:06:01 +0000

I am currently experiencing some crashing due to an NSWindow's _performClose method being called after the document (which was its delegate) is freed. It looks like there is something wrong in the NSDocument infrastructure, because the _window ivar is never retained by NSDocument, but it is released on -dealloc (possibly this should be a -performClose or similar, because NSWindow is meant to retain itself and release itself when it is closed?).

This usually doesn't make much difference, because the window controller takes ownership, and then sets the _window ivar in the document to nil, and so the release message is sent to nil instead of the window.

The problem comes if you follow the common pattern of setting the document (the file's owner) as the window's delegate in the nib. In order for this not to crash when the window sends a respondsToSelector: message to the delegate while closing, the document must remove itself as the delegate before it exists. This would be easy, except that the window controller has stolen the window and the window controller itself has removed itself from the array of window controllers by the time -dealloc is called, so there is no way for an NSDocument subclass to get the window in -dealloc and do this removal...


-- Sent from my Apple II

reply via email to

[Prev in Thread] Current Thread [Next in Thread]