• 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: Andrew Merenbach <email@hidden>
  • Date: Tue, 29 Nov 2005 19:56:26 -0800

I'm afraid that I'm no expert here, and I'm not positive that this would solve a great many problems, but in order to make more people happy with what's been suggested, how about a 'shouldCleanUp' variable (BOOL) type--set to NO in the -init method?

Every time that the overridden release is called, nothing will be done--unless 'shouldCleanUp' has been set to YES through an accessor, in which case dealloc will not be *explicitly* summoned, but (assuming that the client's memory management is correct) will at least have a fair shot of being called.

Notifications do look a good way to clean things up (although we've all discussed the ideas of *philosophy,* too, of which I have little ;) ), but I've not used a huge number of singletons, so I can't offer much more.

Best,
	Andrew


On Nov 29, 2005, at 5:09 PM, David Gimeno Gost wrote:

On 29 Nov 2005, at 23:58, Andreas Mayer wrote:

I'm not saying that everyone should use object deallocation to do resource cleanup, I'm just saying that there is nothing wrong about doing things that way,

It's wrong when you are using Cocoa because you can't be sure that dealloc will be called at all.


Sending an additional release won't help since there might be other objects that are still holding on to the object in question.

And this is exactly the behavior that I would expect. Either those other objects are also released or they aren't. If they are, their - dealloc method shall send the required -release message. If they aren't, that would be a bug in my code, not an incompatibility with the Cocoa model.


Note also that for this to happen to a singleton, it requires that the object that is retaining it is ignoring the fact that it is a singleton.

It's best to not fight the framework. To do so will make your life miserable.

Agreed, but that's not the case.

Regards.

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


This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

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>)
 >Re: Is Apple's singleton sample code correct? (From: glenn andreas <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: Ondra Cada <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: Ondra Cada <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Serge Cohen <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Darkshadow <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: Andreas Mayer <email@hidden>)
 >Re: Is Apple's singleton sample code correct? (From: David Gimeno Gost <email@hidden>)

  • Prev by Date: RE: Is Apple's singleton sample code correct?
  • Next by Date: Re: Coredata and faulting
  • 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