Re: Cleaning up a singleton
Hi, Would the following NSApplication methods, placed into your application delegate's code, help at all? - (void)applicationDidFinishLaunching:(NSNotification *)aNotification; - (void)applicationWillTerminate:(NSNotification *)aNotification; Of the latter, the docs say that one should Put any necessary cleanup code in this method. Cheers, Andrew On May 23, 2008, at 11:07 PM, Sebastian Nowicki wrote: Hi, I have a bit of an odd problem, which may be the result of a bad design decision. My program wraps around a C library, which internally uses a global variable (structure) to manage things, and has functions to access the data. The library requires me to call a function which allocates memory to that global variable, and afterwards call a function which deallocates that memory. My singleton class calls the function to initialise in the init method, but I don't know how to deallocate the memory. Since singleton objects exist until the end of program execution, I assume dealloc wouldn't work with garbage collection. Calling dealloc on a singleton object doesn't even make sense. How would I handle this? -- Sebastian Nowicki ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/andrew.merenbach%40ucla.edu This email sent to [EMAIL PROTECTED] smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Cleaning up a singleton
Am 24.05.2008 um 08:07 Uhr schrieb Sebastian Nowicki: The library requires me to call a function which allocates memory to that global variable, and afterwards call a function which deallocates that memory. My singleton class calls the function to initialise in the init method, but I don't know how to deallocate the memory. [...] How would I handle this? Um. You don't? Since all memory is reclaimed when the application quits, deallocating a singleton to free memory is not necessary. If, for some other reason, you need to act when the application quits, you can register for the NSApplicationWillTerminateNotification notification. Andreas ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Cleaning up a singleton
On 24/05/2008, at 3:48 PM, Andreas Mayer wrote: In case you use the notification, there is no need to expose anything. You just register a method of your singleton to receive the NSApplicationWillTerminateNotification and do your cleanup there. On Apple's developer website there are several example projects that make use of this. Here's one: http://developer.apple.com/samplecode/CapabilitiesSample/listing5.html You need only look at the -init and the -applicationWillTerminate: methods. Andreas Oh, that is awesome. Thanks for pointing it out. -- Sebastian Nowicki ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]