Subject: [Boost-bugs] [Boost C++ Libraries] #10100: [signals2] trackable fails to disconnect slot on deletion
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-06-06 15:47:45
#10100: [signals2] trackable fails to disconnect slot on deletion
------------------------------+----------------------
Reporter: wim@⦠| Owner: fmhess
Type: Bugs | Status: new
Milestone: To Be Determined | Component: signals2
Version: Boost 1.55.0 | Severity: Problem
Keywords: |
------------------------------+----------------------
I ran into a situation where boost.signals correctly tracks the lifetime
of an object, whereas boost.signals2 fails to track the lifetime of the
object.
My best guess is that there is probably a shared_ptr somewhere in the
stack trace of the 'fooer' slot invocation that can be replace by a
weak_ptr. The assumption is that that shared_ptr keeps the connection
alive while it should die.
Full test demonstrating the problem:
{{{
#include <boost/signals2.hpp>
class TrackedObject: public boost::signals2::trackable
{
public:
TrackedObject() {
fooer.connect(boost::bind(&TrackedObject::foo, this));
}
~TrackedObject() { std::cout << "Deleted!" << std::endl; }
void foo();
boost::signals2::signal<void()> fooer;
};
class Tracker
{
public:
Tracker::Tracker(TrackedObject *object)
{
connection_ = signal_.connect(boost::bind(&TrackedObject::foo,
object));
}
bool deleted() const
{
return !connection_.connected();
}
private:
boost::signals2::signal<void()> signal_;
boost::signals2::connection connection_;
};
void TrackedObject::foo()
{
Tracker tracker(this);
delete this;
if (tracker.deleted())
std::cout << "Object was deleted" << std::endl;
else
std::cout << "Object was not deleted" << std::endl;
}
int main(int argc, char **argv)
{
TrackedObject *t = new TrackedObject();
t->fooer(); // does not work
//t->foo(); // works
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/10100> 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:50:16 UTC