Tool to find memory leaks

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Tool to find memory leaks

Post 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.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: Tool to find memory leaks

Post by Manolo »

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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.
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Tool to find memory leaks

Post by T-Rex »

Visual Leak Detector worked fine for me in VS
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post by ONEEYEMAN »

T-Rex,
For VLD crashed the program and it didn't even started.

Thank you.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Tool to find memory leaks

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Tool to find memory leaks

Post 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?
User avatar
T-Rex
Moderator
Moderator
Posts: 1248
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Re: Tool to find memory leaks

Post by T-Rex »

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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.
Attachments
VLD disassembly.png
VLD with pdb.png
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Tool to find memory leaks

Post 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)
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Tool to find memory leaks

Post 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?
Post Reply