• 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: C++ static destructors and shared library unloading?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ static destructors and shared library unloading?


  • Subject: Re: C++ static destructors and shared library unloading?
  • From: Adin Hunter Baber <email@hidden>
  • Date: Thu, 18 May 2006 21:26:37 -0500


On 2006 May 18, at 5:59 PM, Mark Alldritt wrote:

Hi Folks,

I'm struggling with a problem where I'm experiencing crashes when my app
exits. The crashes happen when the C++ run-time invokes a static C++
destructors. My static C++ objects are created in the main application, but
rely on C++ objects from a loaded framework. It appears that these
destructors are begin invoked after my framework has been unloaded, and so
they calling missing framework code.


Is there something special I need to do in Xcode to ensure that static C++
destructors are invoked before frameworks are unloaded?



This is really an Xcode question. You might want to try the carbon- dev list. Though in truth, your problem seems to be more of a pure C+ + issue.


The real simple answer: What you need to do is make sure the static objects are all destroyed before you unload the library.


Other things that might help.

If the static classes are actually singleton objects, do a search on creating and destroying singletons. The Loki library by Alexandrescu might be something for you to check out.

Another thing you can do is keep a reference count associated with the framework. As each object requiring the framework is created, the reference count goes up. As each object is destroyed, the reference count goes down. Once the reference count goes to zero, it is safe to unload. Any calls to unload the library would actually set a flag to indicate that the library may be unloaded once the reference count goes to zero. You could have the framework automatically load and unload with this method. However, that could create a performance issue if you have a situation where only one object is created and destroyed repeatedly.

Another way thing to do it is have a list keep track of all the framework dependent object, and force their destruction before you want to unload the framework. This could create interesting issues if you still want to use the objects however. So going with the reference counting method above would be better in my opinion.

Adin Hunter Baber
email@hidden



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


References: 
 >C++ static destructors and shared library unloading? (From: Mark Alldritt <email@hidden>)

  • Prev by Date: Building sqlite universal [was:Re: .a under version control]
  • Next by Date: Re: Building sqlite universal [was:Re: .a under version control]
  • Previous by thread: C++ static destructors and shared library unloading?
  • Next by thread: GDB
  • Index(es):
    • Date
    • Thread