
Emil Dotchevski wrote:
I have strong suspicions that the changes in boost::function made today introduce a serious bug in the lifetime management of the contained object. ... Reverting to revision 48607 makes the shared_ptr refcount correct.
Thank you, Emil! Douglas has fixed the issue just a few hours ago: http://svn.boost.org/trac/boost/changeset/48627 See also: http://svn.boost.org/trac/boost/ticket/1910#comment:6
Here's a simple test case, I tried it with msvc 9:
#include "boost/function.hpp"
int instances=0; struct X { X() { ++instances; } X(X const &) { ++instances; } ~X() { --instances; } void operator()() { } }; boost::function<void()> f() { return X(); }
int main( int argc, char const * argv[] ) { boost::function<void()> f2; f2=f(); assert(instances==1); }
I just tried your little test case. Before Doug's fix [48627], "instances" was -1 during the assert, now it's 1 again, as it should. :-) So now we have a boost::function::swap function that significantly outperforms std::swap<boost::function>, when swapping large functors. :-) Kind regards, Niels