|
Boost Users : |
Subject: [Boost-users] boost::bind memory leak
From: bit bit (g_rambot_at_[hidden])
Date: 2010-11-11 18:44:44
I am using a shared_ptr to execute code on method exit as instructed in http://www.boost.org/doc/libs/1_44_0/libs/smart_ptr/sp_techniques.html#on_block_exit
shared_ptr<void> shutdown(static_cast<void*>(0), bind(&Thread::AnnounceShutdown, this, ref(state_lock)));
The above line of code causes a memory leak when an exception is thrown inside AnnounceShutdown(). I know I am not supposed to throw inside a destructor, but in this particular case I see no reason for a memory leak. AnnounceShutDown() does not allocate memory. I suspect ref() has something to do with that.
debugger report:
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 14928 at 0x00000000006E6FF0: 56 bytes ----------
Call Stack:
d:\program files\boost\boost_1_44_0\boost\smart_ptr\detail\shared_count.hpp (124): boost::detail::shared_count::shared_count<void * __ptr64,boost::_bi::bind_t<void,boost::_mfi::mf1<void,bIt::Thread,boost::upgrade_lock<boost::shared_mutex> & __ptr64>,boost::_bi::list2<boost::_bi::value<bIt::Thread * __ptr64>,boost::reference_wrapper<boos
d:\program files\boost\boost_1_44_0\boost\smart_ptr\shared_ptr.hpp (199): boost::shared_ptr<void>::shared_ptr<void><void,boost::_bi::bind_t<void,boost::_mfi::mf1<void,bIt::Thread,boost::upgrade_lock<boost::shared_mutex> & __ptr64>,boost::_bi::list2<boost::_bi::value<bIt::Thread * __ptr64>,boost::reference_wrapper<boost::upgrade
d:\ptyxiaki\owner\owner\thread\thread.cpp (690): bIt::Thread::Main
...
..
.
I have already resolved this issue using BOOST_SCOPE_EXIT instead of shared_ptr, but I am looking forward for a better solution with shared_ptr.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net