View Full Version : is there a cocoa class dealloc method?
imported_kelvin
2004.08.10, 03:43 PM
I'm writing a class that opens a system resource in the +initialize method for instances to be created from. Is there a class method like -dealloc where I can close the system resource when my app quits? If not, how would I go about closing the resource?
nabobnick
2004.08.10, 04:32 PM
There isn't one to my knowledge, just write a class method and call it when you terminate your program and that should do the trick. I was thinking this same thing the other day when I was perusing my copy of the Objective-C pocket reference.
Jake McArthur
2004.08.10, 07:57 PM
If not, how would I go about closing the resource?
I'm not sure about whether there is one already, but maybe you could create the resource as a static object, then send that object retains and releases as your program creates and destroys instances of your class. That way, when the last instance of your class is released, all the necessary release messages have been sent to that static object, which calls its dealloc method.
Just an idea. Not tested or even thought through very far.
arekkusu
2004.08.10, 08:15 PM
Yes, there is a -dealloc method. Look at the Foundation Reference for NSObject.
anarchie
2004.08.10, 09:09 PM
I think he wants a +dealloc method.
imported_kelvin
2004.08.10, 11:05 PM
I think he wants a +dealloc method. Indeed I do.
anarchie
2004.08.11, 05:16 AM
In your +initialize, you can register for the NSApplicationWillTerminateNotification and do your shutting down there. Classes are objects, so just pass the class as the observer and have a class method like +applicationWillTerminate.
Jake McArthur
2004.08.11, 12:51 PM
Sounds much more elegant than my idea.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.