Where do you put cleanup code for NSDocument sub-classes?
I have a document-based application and I have sub-classed NSDocument and provided the required methods, but my document needs some extensive clean-up (needs to run external tasks etc). Where is the best place to put this? I have tried a few different methods such as: close close: canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo dealloc If I put it in dealloc , sometimes it gets called and other times it does not (pressing Command+Q seems to bypass my document's deallocation), but it is mandatory that this code gets called without failure (unless program unexpectedly terminates).