how to deteck memory leak in visual c++?

This is a discussion on how to deteck memory leak in visual c++? within the Windows Programming forums, part of the Platform Specific Boards category; in linux, there is a wonderful tool Valgrind, which detect memory leak. What about visual c++? Is there any free ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    163

    how to deteck memory leak in visual c++?

    in linux, there is a wonderful tool Valgrind, which detect memory leak. What about visual c++? Is there any free tools? Or is it in build in visual c++?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    yea, i seached msdn, but none is as good as valgrind

  4. #4
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    Visual Leak Detector - Enhanced Memory Leak Detection for Visual C++
    By Dan Moulding

    http://www.codeproject.com/tools/visualleakdetector.asp

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    i tried to download it, but the zip file seems to have problem. do you experienced the problem?

  6. #6
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    I just downloaded the zip and it works for me.

  7. #7
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    VLD is quite good, and I've downloaded it several times. Unless you are just unlucky it should work just fine. Barring that, the MSVC leak detector is decent although not as verbose as VLD.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    silly me! i didn't register for the code project as member, so i can't d/l it! I have finally d/l it and try to install it. but i got errors when compiling my code.

    maybe i have added the files to the wrong place. is it these 2 location?
    C:\Program Files\Microsoft Visual Studio\VC98\Include
    C:\Program Files\Microsoft Visual Studio\VC98\Lib

  9. #9
    Registered User
    Join Date
    Dec 2005
    Posts
    50
    i read about visual leak detector for a while on the site given, and i think there is an instruction on how you would install the visual leak detector...

    i think you just need to place certain files on those directories

  10. #10
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    another option not mentioned yet..
    fluid studios memory manager (MMGR) is what i had used before valgrind.. i still use it sometimes for quick projects.. i have never heard anything bad about it..

    i have never used it in windows.. but im almost positive that it works...

  11. #11
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    silly me! i didn't register for the code project as member, so i can't d/l it! I have finally d/l it and try to install it. but i got errors when compiling my code.

    maybe i have added the files to the wrong place. is it these 2 location?
    C:\Program Files\Microsoft Visual Studio\VC98\Include
    C:\Program Files\Microsoft Visual Studio\VC98\Lib
    FROM THE WEBPAGE:
    ////////////////////////////////////////////////////////////////////
    To use VLD with your project, follow these simple steps:

    1. Copy the VLD library (*.lib) files to your Visual C++ installation's "lib" subdirectory.
    2. Copy the VLD header files (vld.h and vldapi.h) to your Visual C++ installation's "include" subdirectory.
    3. In the source file containing your program's main entry point, include the vld.h header file. It's best, but not absolutely required, to include this header before any other header files, except for stdafx.h. If the source file, include stdafx.h, then vld.h should be included after it.
    4. If you are running Windows 2000 or earlier, then you will need to copy dbghelp.dll to the directory where the executable being debugged resides.
    5. Build the debug version of your project.
    ////////////////////////////////////////////////////////////////////

    I didn't put the libs and include files in Visual C++ installation's "lib" subdirectory. I created a folder called VLD and put them in there and then set the path to them using:

    Tools>Options>Projects>VC++ Directories
    And put my path in the include and lib files "Show directories for:" section.

    When I first tried it I got a few errors because I had put the vld.h after some include files. Once I put them before the other include files the errors cleared up and it worked.

    It has been a great tool.

  12. #12
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    cartoonlarry, i tried your method, but should have the same problem

    xpand.obj : error LNK2005: __VLD_configflags already defined in data.obj
    expand.obj : error LNK2005: __VLD_maxtraceframes already defined in data.obj
    expand.obj : error LNK2005: __VLD_maxdatadump already defined in data.obj
    Debug/quasibiclique.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.

    I have one header file and I add #include <vld.h> in the first line of the header. Is this wrong?

    xhi, i tried the mmgr, but also have error
    d:\codes\data.h(3) : fatal error C1083: Cannot open include file: 'streamio': No such file or directory
    expand.cpp
    d:\codes\data.h(3) : fatal error C1083: Cannot open include file: 'streamio': No such file or directory
    mmgr.cpp
    d:\codes\mmgr.cpp(77) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Error executing cl.exe.
    Creating browse info file...
    BSCMAKE: error BK1506 : cannot open file '.\Debug\data.sbr': No such file or directory
    Error executing bscmake.exe.

  13. #13
    xhi
    xhi is offline
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    those errors dont ring a bell for me..

    i can tell you how i use it.. which as far as i know is the right way..
    include the mmgr.h file after the standard includes, iostream string. etc.. but before any of your header files.. include mmgr.h in every header in the project.. and you will need to compile and link mmgr.cpp to the project for it all to work..

    maybe you already have this down.. but its worth mentioning..

    example usage
    Code:
    #ifndef ANIMATEDIOS_H
    #define ANIMATEDIOS_H
    
    #include <SDL/SDL.h>
    #include <iostream>
    #include <string>
    
    #include "mmgr.h"
    
    #include "IOS.h"
    that is how i used it in an old file..

    good luck..

  14. #14
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    cartoonlarry, i tried your method, but should have the same problem
    Have you tried to see if it will work with a very simple test app.

    I did a quick test with them using Visual C++ installation's "include" and "lib" subdirectories:

    I put vld.h and vldapi.h in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include

    I put vld.lib, vldmt.lib, and vldmtdll.lib in C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib

    I created a very simple Win32 Console project:

    Code:
    #include <vld.h>
    
    int main()
    {
    	int *leak = new int;
    	return 0;
    }
    After running in Debug mode here are my results:

    Visual Leak Detector Version 1.0 installed (single-threaded static).
    WARNING: Visual Leak Detector detected memory leaks!
    ---------- Block 46 at 0x00896BF0: 4 bytes ----------
    Call Stack:
    c:\dev\vldtest\main.cpp (5): main

    f:\vs70builds\3077\vc\crtbld\crt\src\crt0.c (259): mainCRTStartup
    0x7C816D4F (File and line number not available): RegisterWaitForInputIdle
    Data:
    CD CD CD CD ........ ........

    Visual Leak Detector detected 1 memory leak.
    'VLDTest.exe': Unloaded 'C:\WINDOWS\SYSTEM32\dbghelp.dll'
    'VLDTest.exe': Unloaded 'C:\WINDOWS\SYSTEM32\version.dll'
    Visual Leak Detector is now exiting.
    The program '[3540] VLDTest.exe: Native' has exited with code 0 (0x0).

    /////////////////////////////////////////////////////////

    I have also used it in large applications and haven't had any problems. I usually put the VLD include in my main.cpp just before my other includes.

    Hope this helps.

  15. #15
    Registered User
    Join Date
    Nov 2009
    Posts
    1
    Quote Originally Posted by franziss View Post
    cartoonlarry, i tried your method, but should have the same problem

    xpand.obj : error LNK2005: __VLD_configflags already defined in data.obj
    expand.obj : error LNK2005: __VLD_maxtraceframes already defined in data.obj
    expand.obj : error LNK2005: __VLD_maxdatadump already defined in data.obj
    Debug/quasibiclique.exe : fatal error LNK1169: one or more multiply defined symbols found
    Error executing link.exe.

    I have one header file and I add #include <vld.h> in the first line of the header. Is this wrong?

    xhi, i tried the mmgr, but also have error
    d:\codes\data.h(3) : fatal error C1083: Cannot open include file: 'streamio': No such file or directory
    expand.cpp
    d:\codes\data.h(3) : fatal error C1083: Cannot open include file: 'streamio': No such file or directory
    mmgr.cpp
    d:\codes\mmgr.cpp(77) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Error executing cl.exe.
    Creating browse info file...
    BSCMAKE: error BK1506 : cannot open file '.\Debug\data.sbr': No such file or directory
    Error executing bscmake.exe.


    HI
    I faced a similar problem ...
    reason was , i had included "vld.h" in more than 1 file .
    may be thats the same reason for you

    Deepak

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Memory leak trackers
    By Darkness in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-30-2004, 02:03 PM
  4. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 01:51 PM
  5. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 01:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21