• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Guidelines for Cocoa frameworks supporting garbage collection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Guidelines for Cocoa frameworks supporting garbage collection?


  • Subject: Re: Guidelines for Cocoa frameworks supporting garbage collection?
  • From: Bill Cheeseman <email@hidden>
  • Date: Sun, 06 Jul 2008 08:48:06 -0400
  • Thread-topic: Guidelines for Cocoa frameworks supporting garbage collection?

on 2008-07-05 6:14 PM, William J. Cheeseman at email@hidden 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@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com

PreFab Software - www.prefabsoftware.com


_______________________________________________

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

  • Follow-Ups:
    • Re: Guidelines for Cocoa frameworks supporting garbage collection?
      • From: Quincey Morris <email@hidden>
References: 
 >Re: Guidelines for Cocoa frameworks supporting garbage collection? (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Guidelines for Cocoa frameworks supporting garbage collection?
  • Next by Date: Re: Stopping actions mid stream
  • Previous by thread: Re: Guidelines for Cocoa frameworks supporting garbage collection?
  • Next by thread: Re: Guidelines for Cocoa frameworks supporting garbage collection?
  • Index(es):
    • Date
    • Thread