Does boost bind increment the ref count of a shared_ptr parameter for it's lifetime? For example, take the following code:
void myFunc(boost::shared_ptr<MyClass> in) {
in->doThing();
}
void myOtherFunc() {
{
boost::shared_ptr<MyClass> p = ...;
// A
boost::function<void(boost::shared_ptr<MyClass>)> f = boost::bind(&myFunc, p);
// B
}
// C
}
If bind does increment the ref count, ref should be 1 at A, 2 at B and 0 at C.
Yes, boost::bind
(as well as std::bind
) creates functor that holds copies of the parameters, but one can't count on the number of copies made. So, all you can assume is that at the point (B) the number of references is greater than it was at point (A). Certainly, when the functor gets detroyed, all the shared_ptr
's that it held are released.