Boost::shared_ptr and memory leaks
Hello,
I have wrote simple programm:
using namespace boost;
shared_ptr<int> a(new int(10));
shared_ptr<int> b;
b=a;
a.reset(new int(20));
std::cout<<"a=="<<*a<<" b=="<<*b;
return 0;
Checking this programm with DevPartner BoundsChecker, i found memory
leak:
Type Quantity Total (bytes) Allocation Location Sequence
Leak exiting program 1 84 setlocale - [setlocal.c, line 547 (Boostt.exe)] 9
Memory Leak Exiting Program: Address 0x00E44F88 (84) allocated by _malloc_dbg.
INsideR wrote:
I have wrote simple programm: using namespace boost; shared_ptr<int> a(new int(10)); shared_ptr<int> b; b=a; a.reset(new int(20)); std::cout<<"a=="<<*a<<" b=="<<*b; return 0;
Checking this programm with DevPartner BoundsChecker, i found memory leak: Type Quantity Total (bytes) Allocation Location Sequence Leak exiting program 1 84 setlocale - [setlocal.c, line 547 (Boostt.exe)] 9 Memory Leak Exiting Program: Address 0x00E44F88 (84) allocated by _malloc_dbg.
Where is the problem? May be i write incorrect code?
Looks like your iostream implementation is allocating memory and does not free it. Or your memory checker is buggy. Or both ;-) I suspect that if you remove all lines which create/modify shared_ptr instances, the leak will be still there. - Volodya
Best Wishes, Yury mailto:insider83@inbox.lv
participants (2)
-
INsideR
-
Vladimir Prus