title: Calling the destructor of static objects in a shared library
body: <p>I have implemented singleton of Meyers and four function to work with it. For example:</p>
  <pre><code>//A.h
  class A
  {
  private:
    Device d;
  public:
    A(){//...}
    ~A(){d.release();}
  }
  </code></pre>
  <p>My class singleton Meyers</p>
  <pre><code>//Controller.h
  class Controlle
  {
  private:
  //some members
   A m_member;
  
   Controller();
   Controller(const Controller&amp;);
   Controller&amp; operator=(const Controller&amp;);
  public:
    static Controller&amp; GetInstance()
    {
      static Controller instance;
      return instance;
    }
  }
  </code></pre>
  <p>And interface for working the class of Controller</p>
  <pre><code>extern &quot;C&quot; API Result InitDevice(const ParamsDevice* param);
  extern &quot;C&quot; API Result InitAlgorithm(const ParamAlgorithm* param);
  extern &quot;C&quot; API Result Operation_1();
  extern &quot;C&quot; API Result Operation_2();
  </code></pre>
  <p>I build the library and get the Controller.dll and Controller.lib files. Library is shared lib.
  Then I create a program where Controller.dll is used (implicit). Runtime library exception is thrown after program termination. I compiled the library in debug to check where the exception is thrown from.
  I am getting the exception from comip.h file from method Release() class</p>
  <pre><code>template&lt;typename _IIID&gt; class _com_ptr_t
  {
  public:
      // Declare interface type so that the type may be available outside
      // the scope of this template.
      //
      typedef _IIID ThisIIID;
      typedef typename _IIID::Interface Interface;
      ........
      // Provides error-checking Release()ing of this interface.
      //
      void Release()
      {
          if (m_pInterface == NULL) {
             _com_issue_error(E_POINTER);
          }
          else {
             m_pInterface-&gt;Release();
             m_pInterface = NULL;
          }
      }
  }
  </code></pre>
  <p>I think that when the program terminates, the resources of static objects that are used in the library are incorrectly released. If I replace the singelton Meyers with a classic singelton and create methods for explicitly freeing up the memory of a static pointer, then everything works well. Could you help me explain this effect?</p>
  <p>I think there is an answer to my question, but it is not complete for me and I cannot understand
  <a href="https://stackoverflow.com/a/50644725/13970084">https://stackoverflow.com/a/50644725/13970084</a></p>
  <p>P.S. Sorry for my English. English isn't my native language.</p>