Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4089: Memory leak in Boost.Signals2 when the signal is not invoked
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-06-27 14:48:45
#4089: Memory leak in Boost.Signals2 when the signal is not invoked
-------------------------------+----------------------
Reporter: dan.berindei@⦠| Owner: fmhess
Type: Bugs | Status: reopened
Milestone: To Be Determined | Component: signals2
Version: Boost 1.55.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+----------------------
Changes (by julien.puydt@â¦):
* status: closed => reopened
* version: Boost 1.42.0 => Boost 1.55.0
* resolution: fixed =>
* milestone: Boost 1.43.0 => To Be Determined
Comment:
The following code gives wrong results with 1.55.0 ; it shows kept
references trough a disconnection, which get released only if the signal
is triggered :
{{{
#include <boost/smart_ptr.hpp>
#include <boost/signals2.hpp>
#include <iostream>
void
print (boost::shared_ptr<int> & ptr)
{
std::cout << "Pointer has use count: " << ptr.use_count () << std::endl;
}
int
main (int argc,
char* argv[])
{
boost::signals2::signal<void(void)> sig;
boost::shared_ptr<int> ptr(new int);
// one ref here: should be 1
print (ptr);
boost::signals2::connection conn = sig.connect (boost::bind (&print,
ptr));
// one ref here, one in the bind: should be 2
print (ptr);
// is supposed to release the bind reference
conn.disconnect ();
// one ref here: should be 1
print (ptr);
// this isn't supposed to release a reference!
sig ();
// one ref here: should be 1
print (ptr);
return 0;
}
}}}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4089#comment:3> 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