Jump to: navigation, search

Dead C++ Society/Material/global objects

Revision as of 00:30, 6 February 2014 by Daknob (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Dead C++ Society/Material/global objects


  • Constructor call order
  • Destructor call order
  • Dynamic library load order
  • Many things are forbidden to do in DllMain() (windows)
  • Constructors/destructors can throw
  • Static data storage may not be initialized on some platforms
  • Static data storage may be different between different plugins on some platforms


  • Simple solution:
    • Pros/cons: destructor is never run
A *getA()
  static A *instance = new A;
  return instance;
  • Another simple solution:
    • Pros: No leak - valgrind shows better results
    • Cons: Destructor call order still a problem
A *getA()
  static A instance;
  return &instance;