Ejemplo n.º 1
0
static void find_unreachable_objects_impl(map_type const & m, map2_type & m2)
{
    // scan objects for shared_ptr members, compute internal counts

    {
        std::cout << "... " << m.size() << " objects in m.\n";

        for(map_type::const_iterator i = m.begin(); i != m.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);

            BOOST_ASSERT(p->use_count() != 0); // there should be no inactive counts in the map

            m2[ i->first ];

            scan_and_count(i->second.first, i->second.second, m, m2);
        }

        std::cout << "... " << m2.size() << " objects in m2.\n";
    }

    // mark reachable objects

    {
        open_type open;

        for(map2_type::iterator i = m2.begin(); i != m2.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);
            if(p->use_count() != i->second) open.push_back(p);
        }

        std::cout << "... " << open.size() << " objects in open.\n";

        for(open_type::iterator j = open.begin(); j != open.end(); ++j)
        {
            m2.erase(*j);
        }

        while(!open.empty())
        {
            void const * p = open.front();
            open.pop_front();

            map_type::const_iterator i = m.find(p);
            BOOST_ASSERT(i != m.end());

            scan_and_mark(i->second.first, i->second.second, m2, open);
        }
    }

    // m2 now contains the unreachable objects
}
Ejemplo n.º 2
0
void find_unreachable_objects_impl(arena_type const & m,
                                   reachable_object_type & m2, bool report)
{
    // scan objects for shared_ptr members, compute internal counts

    {
        if (report)
            std::cout << "... " << m.size() << " objects in the world\n";

        for(arena_type::const_iterator i = m.begin(); i != m.end(); ++i)
        {
            phxpr::detail::sp_counted_base const * p = 0;

            p = static_cast<phxpr::detail::sp_counted_base const *>(i->first);

            // there should be no inactive counts in the map
            BOOST_ASSERT(p->use_count() != 0); 

            m2[ i->first ];

            if (i->second.first)
                scan_and_count(i->second.first, i->second.second, m, m2);
        }
    }

    // mark reachable objects

    {
        open_type open;

        for(reachable_object_type::iterator i = m2.begin(); i != m2.end(); ++i)
        {
            phxpr::detail::sp_counted_base const * p
                = static_cast<phxpr::detail::sp_counted_base const *>(i->first);
            if(p->use_count() != i->second) open.push_back(p);
        }

        if (report)
            std::cout << "... " << open.size() << " objects are directly reachable\n";

        for(open_type::iterator j = open.begin(); j != open.end(); ++j)
        {
            m2.erase(*j);
        }

        while(!open.empty())
        {
            void const * p = open.front();
            open.pop_front();

            arena_type::const_iterator i = m.find(p);
            BOOST_ASSERT(i != m.end());

            if (i->second.first)
                scan_and_mark(i->second.first, i->second.second, m2, open);
        }
    }

    // m2 now contains the unreachable objects

    if (report)
        std::cout << "... " << m2.size() << " objects are unreachable\n";
}