On Wed, Jun 9, 2010 at 11:43 PM, Emil Dotchevski <emil@revergestudios.com> wrote:
2010/6/9 Matheus Araújo Aguiar <matheus.pit@gmail.com>:
> Hello list,
> In my application i am using a shared_ptr to manage the lifetime of some
> important objects. Lately i've been noticing that they are not being
> destroyed (their destructor is never called) and their use count is 9.
> I've started debugging and noticed that if i pass the shared_ptr to
> boost::bind as a parameter when the binded function is executed the
> use_count is greater than what would be expected (in my particular case 4
> instead of one). As i make use of boost::bind, the shared_ptr reaches a
> point where its use_count is way out of expectations, getting to 9.
> So is this expected? Am i incorrectly using boost::bind or shared_ptr in
> this situation?

By design, boost::bind makes copies of all of its arguments and stores
them into the returned function object. If any of these arguments is a
shared_ptr instance, that will increase the refcount. If that's not
desirable, you can instead pass sp.get() to bind. You can also wrap
the arguments using boost::ref/cref if you want bind to store
references instead of copies.
Thanks Emil.

Today I have tracked down the bug in a third-part library i was using: it was never releasing the function objects holding the shared_ptr's.

 Best Regards,

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Matheus Araújo Aguiar
Computer Scientist
matheus.pit@gmail.com