cocoa - NSDocument subclass "close" method called twice -


i have document-based cocoa application subclasses nsdocument mydocument. each mydocument manages separate background process (as nstask). want make sure nstask terminated when corresponding mydocument closes or when whole application quits.

for latter, make document observe nsapplicationwillterminatenotification. former, override close method:

-(void)close {     // cleanup code here     [super close]; } 

(incidentally, can't put cleanup code in dealloc method since project gc'd.)

the problem this: if open mydocument, make unsaved changes , press cmd-q, close method called twice. debugger, call chain is: [mydocument close] calls [nsdocument close], calls [nswindowcontroller _windowdidclose], calls [mydocument close] again. (after call, application quits).

is expected behavior? if so, there better way release document-specific resources? or should make close safe run multiple times?

i believe i've seen post cocoadev mailing list saying normal behaviour frameworks @ moment (but might change in future). should make -close method robust enough handle multiple calls since no guarantee made appkit called once.

i don't believe need care nsapplicationwillterminatenotification, since if understand correctly, tasks automatically terminated when app too. furthermore, if support sudden termination, app can killed without notice/notification anyway.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -