c++c++11memory-leaksshared-ptrvisual-leak-detector

Visual leak detector with std::shared_ptr


I am relatively new to shared_ptr. I'm using visual leak detector and I get errors at the end of the runtime when giving me following code as a memory leak :

std::shared_ptr<the_type>(new the_type(the_parameter))

Do i have to call something else like a deleter or even shared_ptr::reset() , is it visual leak detector that is telling me a false leak or it is running before the shared_ptr is actually being deleted?

Thanks.

note: i use vld 2.2.3, VS2012, Windows 7/8


Solution

  • Without more code, it's hard to say, but one clear possibility is that you have a cycle. Just using std::shared_ptr everywhere is going to lead to problems sooner or later; it's a useful tool for specific cases, but it isn't going to solve all of your problems.