• 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: Greg Titus <email@hidden>
  • Date: Thu, 1 Dec 2005 09:43:27 -0800


On Dec 1, 2005, at 9:27 AM, David Gimeno Gost wrote:

The real issue here is possible cleanup dependencies. Resources may need to be disposed of in a certain order. An object managing certain resources may depend on the services provided by another object to do its own cleanup.

If I've correctly understood the way notifications work, you have little or no control at all over the order in which they will be received. That means that if you have two objects that have registered for the notification and one of them depends on the other to do its job first, then you are in trouble. Also, you may not like the idea of having to add notification registering and handling to every object whose resources must be properly disposed of.

(I've omitted your solution to this problem.)

You seem to be building a lot of complexity for a use case that I've never run into in my 16 years of professional programming. Do you have an example of resource cleanup dependencies that necessitates this kind of solution?

Your discussion of using notifications and releasing singletons from the application delegate implies that the cleanup happens on app exit. Memory and file descriptors/sockets/pipes all get cleaned up by the operating system when the process exits, so no cleanup is generally necessary there. Which usually leaves temporary files and lock files as the types of things which need to be explicitly cleaned up - but the only situations in which I can imagine the order matters are also situations in which the multiple objects are managed by the same singleton (so the ordering is handled internally to a single object). For instance, some temporary file with an associated lock file - if a singleton pattern is involved, there should be only one object managing both these resources. (Or perhaps a singleton for the temp file, which contains another "LockFile" object, which it retains and releases. The point is, only one singleton.)

What is the problem you are attempting to solve here?

Thanks,
-- Greg


_______________________________________________
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: 
 >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: NSSearchField _sendPartialString exception
  • 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