id summary reporter owner description type status milestone component version severity resolution keywords cc 3658 Remove dependency on static initialization/destruction order Andrey Semashev Joaquín M López Muñoz "The static_holder depends on the static initialization/destruction order, as it is implemented as a function-local static variable. If there are flyweights in the static or global variables, which are initialized lazilly, the flyweight value may get destroyed before the flyweights that refer to it. For example: {{{ #include #include #include #include #include struct A { int m_n; A(int n) : m_n(n) { std::cout << ""A()"" << std::endl; } ~A() { std::cout << ""~A()"" << std::endl; } bool operator== (A const& a) const { return m_n == a.m_n; } friend std::size_t hash_value(A const& a) { return a.m_n; } }; struct B { boost::flyweight< boost::flyweights::key_value< int, A > > m_A; B() : m_A(10) { std::cout << ""B()"" << std::endl; } ~B() { std::cout << ""~B()"" << std::endl; } }; boost::shared_ptr< B > p; int main(int, char*[]) { p.reset(new B()); return 0; } }}} Compiled with MSVC: {{{ cl -Ox -MD -EHsc -I . -DNDEBUG ./flyweight_test.cpp }}} Produces: {{{ A() B() ~A() ~B() }}} And a crash. A possible solution would be to destroy flyweight values only when reference counter from flyweights drops to zero. " Feature Requests closed Boost 1.42.0 flyweight Boost 1.41.0 Problem invalid