Search for who creates an object using a smart pointer

I posted a few days ago about memory leaks with smart pointers. Now I can find out what objects are memory leaks, but I can not understand where they come from memory leak.

I use the same code as here. Memory leak detection in counted objects

I read a lot of comments, but none of them explained correctly. I tried using the FILE and LINE macros, both of them print the file and line of the refmanager class.

Is there a good way to debug this problem. See also a good example.

+1
source share
2 answers

The easiest way is to use Valgrind (on Linux and Mac) and a similar tool for Windows.

You can also take a backtrace (using the backtrace () function on Linux and Mac) or a similar function from dbghelp.dll on windows in the smart pointer constructor, and then save the return line somewhere to the selection and remove the backtrace to free. Then print all remaining return paths at the output.

+1
source

On Windows, you can use the new memory diagnostic tools in Visual Studio 2015:

0
source

Source: https://habr.com/ru/post/927401/


All Articles