Subject: [Boost-bugs] [Boost C++ Libraries] #2338: sp_collector.cpp reports reachable objects as unreachable
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-09-17 22:12:18
#2338: sp_collector.cpp reports reachable objects as unreachable
--------------------------+-------------------------------------------------
Reporter: pdimov | Owner: pdimov
Type: Bugs | Status: new
Milestone: Boost 1.37.0 | Component: smart_ptr
Version: Boost 1.36.0 | Severity: Problem
Keywords: |
--------------------------+-------------------------------------------------
Jim Barry in http://lists.boost.org/boost-users/2008/09/40507.php:
{{{
I am trying to detect circular references using the
find_unreachable_objects function in sp_collector.cpp. However, it reports
false positives in the simple case of one object being owned by another.
To illustrate:
#define BOOST_SP_ENABLE_DEBUG_HOOKS
#include <boost/shared_ptr.hpp>
// sp_collector.cpp exported functions
std::size_t find_unreachable_objects(bool report);
struct X {};
struct Y
{
boost::shared_ptr<X> pX;
Y() : pX(new X) {}
};
int main()
{
boost::shared_ptr<Y> y(new Y);
find_unreachable_objects(true);
return 0;
}
The output is as follows:
... 2 objects in m.
... 1 objects in m2.
... 1 objects in open.
Unreachable object at 0036BA60, 12 bytes long.
Clearly this is incorrect as there are no circular references. Looking at
the code, there is what appears to be a typo at line 124:
std::cout << "... " << m2.size() << " objects in open.\n";
should be:
std::cout << "... " << open.size() << " objects in open.\n";
But the real problem seems to be at line 121:
if(p->use_count() != i->second) open.push_back(p);
I'm not entirely sure what's going on in this section of code, but it ends
up determining (incorrectly) that the "X" object is unreachable.
}}}
-- Ticket URL: <http://svn.boost.org/trac/boost/ticket/2338> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC