• 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: Is Apple's singleton sample code correct?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Apple's singleton sample code correct?


  • Subject: Re: Is Apple's singleton sample code correct?
  • From: glenn andreas <email@hidden>
  • Date: Mon, 28 Nov 2005 13:29:37 -0600


On Nov 28, 2005, at 12:35 PM, David Gimeno Gost wrote:

On 28 Nov 2005, at 09:10, Christian Brunschen wrote:

One can never be certain that any application will actually be properly terminated

Yes. And that's precisely the reason you shoud strive to have a uniform and consistent way of disposing of resources, no matter how your application terminates, no matter when. Destructors (or whatever they are called in any particular OO language) are widely considered the best way to provide such a uniform and consistent approach. I'm not going to argue here why they are indeed the best approach.




Objective-C does not have "Destructors".

Even "dealloc" is just a convention of the class library used (one could write a different class library that doesn't have dealloc at all), as is the whole reference counting, etc... Cocoa simply has a method that is called by the NSObject's "release" method when its reference count reaches zero.

C++ has explicit destructors that have language defined behavior - Objective-C does not.

So expecting Cocoa's dealloc to be semantically identical to a C++ dtor is going to cause problems.

Cocoa _does_ provide a mechanism to provide cleanup when the application terminates - registering for NSApplicationWillTerminate notification. It not only works well in theory, but works well in practice as well. There's no need to "fight against the stream" to try to make Cocoa work like C++ - just use the provided idiom and conventions...


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Is Apple's singleton sample code correct?
      • From: David Gimeno Gost <email@hidden>
References: 
 >Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Shawn Erickson <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Uli Kusterer <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Uli Kusterer <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: mmalcolm crawford <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: mmalcolm crawford <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Christian Brunschen <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)

  • Prev by Date: Re: webviw in a tab
  • Next by Date: [Solved] Re: filterPredicate question
  • Previous by thread: Re: Is Apple's singleton sample code correct?
  • Next by thread: Re: Is Apple's singleton sample code correct?
  • Index(es):
    • Date
    • Thread