How to find memory leaks?

Hello guys, I would first like to thank all of you for helping me out in my coding journey, thank you for helping a fellow Icelandic programmer, this is a great community of C++ programmers. Now, I have written a game in WinAPI (not solitaire, a shooter game this time) and I want to see if it contains any memory leaks. Although I am certain that it does not, I still would like to run some sort of a debugger to determine whether the game is leaking out memory and if so, handle the mess. How can I do that in Visual Studio? I have Visual Studio 2013 Express and Visual Studio Professional 2015.

Thanks!
Why do you need to worry about memory leaks?
It is always a good practice to avoid new and delete keywords, so that you can avoid possible memory leaks in the future.
Last edited on
I find the easiest way to detect (not locate) memory leaks in an interactive application is to run it and observe the memory usage over time using a system monitor. If there are memory leaks, the usage will grow over time.
Thank you Thomas for the links, and thanks Helios for the suggestion, I ended up using the task manager to view memory consumption. =)
And there are tools like valgrind to detect them.
Valgrind is only really for *nix, unfortunately. When you can use it, it's an amazing tool. Although, you might be able to use it alongside Wine or something, though I wouldn't know how would that'd work.
Last edited on
Why do you need to worry about memory leaks?
It is always a good practice to avoid new and delete keywords, so that you can avoid possible memory leaks in the future.

This advice is only applicable to C++11 and up. If you are working on an existing project that uses older variants of the C++ standard you will have to know how to use new, delete, and know how to find memory leaks.

This is basically what Stroustrup says:
A rule of thumb is that, new belongs in constructors and similar operations, delete belongs in destructors. In addition, new is often used in arguments to resource handles. Otherwise avoid using new and delete, use resource handles (smart pointers) instead.
I use Visual Studio 2013 community and the debugger reports detected memory leaks in the output window. I think it does this by default since I didn't configure anything.

Create a small program with memory leak and see whether your VS reports it.
Topic archived. No new replies allowed.