Page 1 of 2

Tool to find memory leaks

Posted: Tue Sep 11, 2018 2:35 pm
by ONEEYEMAN
Hi,
Sorry for the question not specifically related to wx, but I am stuck and don't see the way forward.

I have an application that I recently started compiling with MSVC 2017. Before that I used 2010 version.
The application consist of 1 binary executable and couple of DLLs. It also uses a MT. The application is using wxWidgets 3.1.1 and I'm testing on Windows 8.1.

Somewhere during the process of writing it I introduced a memory leaks.
I tried to inspect the code visually for any new/delete mismatch, but it is very hard as an application is big (not huge yet ;-)).
I tried to switch back to MSVC 2010 and use vld on it, but when I did that the application failed to start and crashed (not asserted).

So, now I'm curious - what is the best solution to find a memory leaks on Windows?
I would've tried to run Linux' valgrind, but my Linux machine is no in service with the hardware issues. And I'm having difficulties with the OSX/Xcode run ATM.

Do you have any suggestions? I prefer MSVC 2017 solution, since 2010 does not implement necessary C++11 feature(s) I'm using. Is there any free or maybe an evaluation tool I can use to check for leakage?

Thank you.

Re: Tool to find memory leaks

Posted: Tue Sep 11, 2018 4:09 pm
by Manolo

Re: Tool to find memory leaks

Posted: Tue Sep 11, 2018 4:56 pm
by ONEEYEMAN
Hi, Manolo,
Thank you for the links.
Most of the packages from the first links are profilers to improve the performance. I'm not there yet, even though it would be nice to do in the near future.
The things that are used for memory leaks are proprietary and cost money, but I found at least one tool that have a trial version and will check that (deleaker).

Thank you.

Re: Tool to find memory leaks

Posted: Mon Sep 17, 2018 11:14 am
by T-Rex
Visual Leak Detector worked fine for me in VS

Re: Tool to find memory leaks

Posted: Mon Sep 17, 2018 2:48 pm
by ONEEYEMAN
T-Rex,
For VLD crashed the program and it didn't even started.

Thank you.

Re: Tool to find memory leaks

Posted: Mon Sep 17, 2018 8:59 pm
by catalin
ONEEYEMAN wrote:VLD crashed the program and it didn't even started.
What VLD version did you use? I suspect it was not the latest, aka 2.5.1, because it des work with VS 2017 too.

Re: Tool to find memory leaks

Posted: Mon Sep 17, 2018 9:20 pm
by ONEEYEMAN
catalin,
No it was not the latest version.
I will try to get the latest one either today or tomorrow and re-try with my program.

Thank you.

Re: Tool to find memory leaks

Posted: Sat Sep 22, 2018 2:08 am
by ONEEYEMAN
catalin,
I'm attaching the screenshot of running my application under MSVC 2017 compiled and linked with the latest VLD.

Do you know how do I fix it? Is there something missing on my Win 8.1 system?

Thank you.
VLD_screenshot.png

Re: Tool to find memory leaks

Posted: Sat Sep 22, 2018 5:56 am
by catalin
How did you use vld in your code?
Is it picking up the [correct] vld dll? BTW, which version is "latest"?

p.s. did you try it in one of the samples?

Re: Tool to find memory leaks

Posted: Sat Sep 22, 2018 10:46 am
by T-Rex

Re: Tool to find memory leaks

Posted: Sat Sep 22, 2018 3:11 pm
by ONEEYEMAN
Hi,
catalin wrote: How did you use vld in your code?
In the binary and every dll in the solution for one file I include vld.h.
In the project properties for executable and all DLL projects I add "vld.lib" in the "Linker->Input" and then added the directory for it in "Linker->General".
catalin wrote: Is it picking up the [correct] vld dll? BTW, which version is "latest"?
I don't see why not. I copied the DLL over to the directory where the binary is.
And I believe the latest version 2.5.1.
catalin wrote: p.s. did you try it in one of the samples?
No, not yet.

Thank you.

Re: Tool to find memory leaks

Posted: Sun Sep 23, 2018 4:06 am
by ONEEYEMAN
Hi,
T-Rex wrote: You should be able to download the Debug Symbols for Windows DLLs from within Visual Studio
https://docs.microsoft.com/en-us/window ... ad-symbols
https://docs.microsoft.com/en-us/window ... bol-server
https://www.screencast.com/t/vsnjdJTLgBq
I grabbed the symbols but nothing helpful came out. See scfreenshots.

Thank you.

Re: Tool to find memory leaks

Posted: Tue Sep 25, 2018 2:54 am
by ONEEYEMAN
Hi, catalin,
catalin wrote: p.s. did you try it in one of the samples?
I just tried to add vld to the minimal sample.

1. Open minimal.vc15 in MSVC 2017.
2. "Build->Configuration Manager...", change "Active Solution Configuration" to be "DLL Debug"
3. In the minimal project for project properties in the "C/C++->General->Additional include directories" add "C:\Program Files (x86)\Visual Leak Detector\include;"
4. In the minimal.cpp add line:

Code: Select all

#include "vld.h"
5. In the "Linker->Additional Dependencies" add "vld.lib;"
6. In the "Linker->General->Additional Library Directories" add "C:\Program Files (x86)\Visual Leak Detector\lib\Win32;"
7. Copy "vld_x86.dll", "wxbase311ud.dll" and "wxmsw311ud_core_custom.dll" to the folder where executable is.
8. Try to debug the resulting application. I got the same crash as I got from my application.

Tell me if I did something wrong. See if you can reproduce this as well.

I'm running MSVC 2017 Community Edition on Windows 8.1.

Thank you.

Re: Tool to find memory leaks

Posted: Tue Sep 25, 2018 5:21 am
by catalin
Did you also copy dbghelp.dll ?

The way it works for me (and always has IIRC):
- add the include dir to "Additional include directories", just like you did;
- add the lib dir to "Additional library directories";
- include "vld.h" in the code as early as possible;
(- so, no vld.lib in "Additional Dependencies", no files copied, at least when running in the debugger)

Re: Tool to find memory leaks

Posted: Tue Sep 25, 2018 12:42 pm
by ONEEYEMAN
Hi, catalin,
catalin wrote: Did you also copy dbghelp.dll ?
Yes, I did.
catalin wrote: The way it works for me (and always has IIRC):
- add the include dir to "Additional include directories", just like you did;
- add the lib dir to "Additional library directories";
- include "vld.h" in the code as early as possible;
(- so, no vld.lib in "Additional Dependencies", no files copied, at least when running in the debugger)
I just tried to remove "vld.lib" from "Linker->Input" and rebuilding.
This is my modified code:

Code: Select all

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif
#include "vld.h"
Is it too late? Should I put it before

Code: Select all

#include "wx/wxprec.h"
?

Thank you.


P.S.: Removing "vld.lib" does not make a difference. Did you build a static configuration and not a DLL one, maybe?