Boost C++ Libraries: Ticket #9553: destruction of flyweights fails from a module which never creates flyweigths https://svn.boost.org/trac10/ticket/9553 <p> Using a factory pattern together with shared_ptr, all flyweight instances are created in one dll only. Due to shared ownership, they might be destroyed from a dll which never creates a single flyweight. Because erase does not call core::init(), the module global state for flyweight management is never initialized, even when using intermodule_holder, leading to a crash when accessed. </p> <p> It is not possible to provide a minimal example, because the example must consist of different modules. </p> <p> The following patch fixes the problem: </p> <pre class="wiki">Index: flyweight/detail/flyweight_core.hpp =================================================================== --- flyweight/detail/flyweight_core.hpp (revision 462875) +++ flyweight/detail/flyweight_core.hpp (revision 462876) @@ -65,6 +65,7 @@ template&lt;typename Checker&gt; static void erase(const handle_type&amp; h,Checker chk) { + core::init(); typedef typename core::lock_type lock_type; lock_type lock(core::mutex()); if(chk(h))core::factory().erase(h); </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9553 Trac 1.4.3 Joaquín M López Muñoz Wed, 15 Jan 2014 19:15:30 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9553#comment:1 https://svn.boost.org/trac10/ticket/9553#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed at </p> <p> <a class="ext-link" href="https://github.com/boostorg/flyweight/commit/7e984210f2f6ac4fed4fcda09cd714b64a5191de"><span class="icon">​</span>https://github.com/boostorg/flyweight/commit/7e984210f2f6ac4fed4fcda09cd714b64a5191de</a> </p> Ticket