• 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
Ordering of static destructors on exit
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ordering of static destructors on exit


  • Subject: Ordering of static destructors on exit
  • From: "Rob Cas" <email@hidden>
  • Date: Wed, 9 Aug 2006 16:14:53 +1000

Hi,

I was wondering if anybody can tell me precisely when the destructors
of static objects are called.

I have been using something like:
CClass* CClass::singleton()
{
static CClass singletonInstance;
return & singletonInstance;
}
inside a framework. This framework is used by a QuickTime component.

CASE A:
In typical applications, the sequence of events I see on quitting the
application is:
- the QuickTime component closed
- destructor of singletonInstance called
- application has exited

CASE B:
In a recent Cocoa application I've come across I'm seeing:
- destructor of singletonInstance called
- the QuickTime component closed
- application has exited (well - application crashes now, as the
singleton is referenced by the QuickTime component)

I had thought that static destructors always were called at exit()
time, so am a little puzzled how the order is reversed by this Cocoa
app. (The destructor and component closing appear to be occurring on
the same pthread.)


Moving the: static CClass singletonInstance; from inside the function, to outside the function (ie. file scope) restores the ordering to that of CASE A, and avoids the crash.


But I don't understand why the change of scope would change the ordering of events...

Can anybody shed any light, or point me at any only resources that
describe how darwin/gcc orders the calling of static destructors?


(This may be a cocoa-dev mailing list question, as I understand Cocoa apps are run/controlled by NSApplicationMain() which may do some special atexit() fiddling...but I thought I'd try here first...)

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


  • Follow-Ups:
    • Re: Ordering of static destructors on exit
      • From: Steve Checkoway <email@hidden>
  • Prev by Date: Re: Intel XNU bug report
  • Next by Date: Re: Ordering of static destructors on exit
  • Previous by thread: Re: Intel XNU bug report
  • Next by thread: Re: Ordering of static destructors on exit
  • Index(es):
    • Date
    • Thread