on 2008-07-05 6:14 PM, William J. Cheeseman at [EMAIL PROTECTED] wrote: > it would be very helpful to have some good examples of ways to > move cleanup code out of dealloc/finalize and into what you call > "deterministic" methods.
It occurs to me that this is a question that will eventually be answered by an evolving Cocoa design pattern, as so many other Cocoa design patterns have evolved over time. Apple's garbage collection documentation very strongly advises us not to implement a -finalize method if at all possible, but instead to do cleanup in a method whose invocation the developer can control -- in order to avoid the problems that can be created by the built-in uncertainty as to when -finalize will be called, not to mention the overhead that would be created at collection time. So here's a possible approach that was suggested to me privately, for use in a framework that supports garbage collection. Comments? @interface MyFrameworkClass : NSObject { BOOL wrappedup; } - (void)wrapup; - (void)someMethod; @end @implementation MyFrameworkClass - (void)finalize { if (!wrappedup) { // protect against inadvertent early termination [self wrapup]; } } - (void)wrapup { // cleanup code goes here wrappedup = YES; } - (void)someMethod { [self wrapup]; } @end -- Bill Cheeseman - [EMAIL PROTECTED] Quechee Software, Quechee, Vermont, USA www.quecheesoftware.com PreFab Software - www.prefabsoftware.com _______________________________________________ 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]