title: NSDocument Subclass not closed by NSWindowController?
body: <p>Okay, I'm fairly new to Cocoa and Objective-C, and to OOP in general.</p>
  
  <p>As background, I'm working on an extensible editor that stores the user's documents in a package.  This of course required some "fun" to get around some issues with <code>NSFileWrapper</code> (i.e. a somewhat sneaky writing and loading process to avoid making <code>NSFileWrappers</code> for every single document within the bundle).  The solution I arrived at was to essentially treat my <code>NSDocument</code> subclass as just a shell -- use it to make the folder for the bundle, and then pass off writing the actual content of the document to other methods.</p>
  
  <p>Unfortunately, at some point I seem to have completely screwed the pooch.  I don't know how this happened, but closing the document window no longer releases the document.  The document object doesn't seem to receive a "close" message -- or any related messages -- even though the window closes successfully.</p>
  
  <p>The end result is that if I start my app, create a new document, save it, then close it, and try to reopen it, the document window never appears.  With some creative subclassing and <code>NSLogging</code>, I managed to figure out that the document object was still in memory, and still attached to the <code>NSDocumentController</code> instance, and so trying to open the document never got past the <code>NSDocumentController's</code> "hmm, currently have that one open" check.</p>
  
  <p>I did have an <code>NSWindowController</code> and <code>NSDocumentController</code> instance, but I've purged them from my project completely.  I've overridden nearly every method for <code>NSDocument</code> trying to find out where the issue is.  So far as I know, my Interface Builder bindings are all correct -- "Close" in the main menu is attached to <code>performClose:</code> of the First Responder, etc, and I've tried with fresh unsullied MainMenu and Document xibs as well.</p>
  
  <p>I thought that it might be something strange with my bundle writing code, so I basically deleted it all and started from scratch, but that didn't seem to work.  I took out my <code>-init</code> method overrides, and that didn't help either.  I don't have the source of any simple document apps here, so I didn't try the next logical step (to substitute known-working code for mine in the <code>readFromUrl</code> and <code>writeToUrl</code> methods).</p>
  
  <p>I've had this problem for about sixteen hours of uninterrupted troubleshooting now, and needless to say, I'm at the end of my rope.  If I can't figure it out, I guess I'm going to try the project from scratch with a lot more code and intensity based around the bundle-document mess.</p>