Re: dealloc for cleanup versus freeing memory
Re: dealloc for cleanup versus freeing memory
- Subject: Re: dealloc for cleanup versus freeing memory
- From: Ron Fleckner <email@hidden>
- Date: Mon, 6 Aug 2007 13:01:47 +1000
Date: Sun, 05 Aug 2007 13:03:56 -0700
From: Kurt Bigler <email@hidden>
Subject: dealloc for cleanup versus freeing memory
To: Cocoa-dev <email@hidden>
There has been discussion on this list in the past relating to
dealloc on
quit.
Cocoa will skip over sending deallocation messages to objects when
your app is about to quit. This is an optimization,
So it may sound like a nice idea that Cocoa optimizes memory
release on
quit, but if this means dealloc is not called it means I have not
done all
the other non-memory related cleanup that I would typically do in
dealloc.
I'm not aware of any other generic place to put such cleanup actions,
besides dealloc, so please inform me if I'm missing something.
You could try - (NSApplicationTerminateReply)
applicationShouldTerminate:(NSApplication *)sender
or - (void)applicationWillTerminate:(NSNotification *)aNotification
From the docs (in NSApplication Class Reference) for the second one:
Discussion
The value of aNotification is always an
NSApplicationWillTerminateNotification. You can retrieve the
NSApplication object in question by sending object to
aNotification. ***Put any necessary cleanup code in this method.***
My specific problem is typical of the kinds of things I saw
reported in
several threads on this list: My custom view is not reliably
getting a
dealloc message on quit.
To make it more mysterious, the view gets a dealloc if the Command-Q
shortcut is used to quit, but not if Quit is selcted from the menu
using the
mouse. If anyone has any clues why this might be, I'd appreciate it.
I also notice that my window delegate never receives a dealloc,
even when
the window is closed explicitly, i.e. via the close button rather than
implicitly due to Quit. (In the close-button case, my custom view
*does*
receive a dealloc message.)
Sorry, I don't know much about that.
Thanks for any info.
No worries.
-Kurt Bigler
Ron
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden