I asked Bjarne this question personally years ago; his answer was: don't make memory leaks.
I found this answer kind of putting your hand in the sand at the time. However now in retrospect I completely agree with it.
Not making memory leaks requires lifetime consideration of objects and data structures. For many data an std::vector is an excellent default container for values.
Also I find the 'everything belongs somewhere' mantra extremely helpful.
When introducing a new object, value or structure, consider who owns it, or who it should at least outlife and how that will be accomplished.
For single objects and native resources an std::unique_ptr<> is very handy. They can have custom destructors to, for example, close a filehandle or release a GDI handle, close a network socket, name it. Anything OS native can be wrapped in raii objects to manage it like that.
This will for the most part eliminate creating leaks in the first place. Some for that thanks to the raii wrappers, smartpointer or containers , but mostly due to the thought that you put into putting things in the right place.
However, in an existing application where years of thought did not go into this and people that did think of it already left, this can be problematic.
In such cases tools can help, such as doctor memory which is free https://drmemory.org/ or Check out https://www.deleaker.com/ which is very user friendly and integrates well with visual studio.
Another option that I use to track memory leaks is to create a counter object, this is a class that contains a static counter that logs the instance number and goes up everytime the class instantiated, and every thing that it leaves scope, logs the instance number and decreases the counter.
If you add such a class as a member of the objects you want to tracks, you can at least see exactly when they are created and destroyed and in what order.
Gr,
Jan
Almost all the plugins that I use are already written here. I want to add:
GitHub Extension. The GitHub Extension for Visual Studio makes it easy to connect to and work with your repositories on GitHub;
Deleaker. Deleaker is a Visual C++ extension and standalone application for memory leak detection - memory, GDI, and handles so far.
SQLite. Connect to SQL Server Compact 4.0, 3.5, SQL Server and SQLite database files in Visual Studio 2012 and later, including the free VS 2013 and later Community Edition
My choice is ReSharper, Markdown editor and Deleaker.