CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2001
    Posts
    703

    Finding or detecting memory leaks?

    hi pals,
    i would like to know whether my application has got memory leaks or not?is there any way that i can find?do help me.Thanks in advance.



    VCVCVC
    "Dont Forget to rate if it helped"

  2. #2
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    Re: Finding or detecting memory leaks?

    Problems with new / delete allocations on the heap can be discovered using this code :


    /////////////////////////////////////////////////////////////////////////////
    // FindMemoryLeaks

    #ifdef _DEBUG

    #include "crtdbg.h"

    class FindMemoryLeaks
    {
    _CrtMemState m_checkpoint;

    public:

    FindMemoryLeaks()
    {
    _CrtMemCheckpoint(&m_checkpoint);
    };

    ~FindMemoryLeaks()
    {
    _CrtMemState checkpoint;
    _CrtMemCheckpoint(&checkpoint);
    _CrtMemState diff;
    _CrtMemDifference(&diff, &m_checkpoint, &checkpoint);
    _CrtMemDumpStatistics(&diff);
    _CrtMemDumpAllObjectsSince(&diff);
    };
    };

    #endif




    Add this code to your applications main cpp file, before your CWinApp based class. Within your apps InitInstance(), add the following code right at the top of that function :


    #ifdef _DEBUG
    FindMemoryLeaks fmt;
    #endif




    When you stop your program on a debug run, the debug output window will detail all allocations with new / malloc, and also report where they haven't been deleted. You can double click on the line in the debug window to take you to the source with the problem (usually a 'new()' statement).

    For other problems such as gdi or windows resource leaks, there are a number of tools and articles on the MSDn site you can find here : http://msdn.microsoft.com/library/de...html/leaks.asp . The gdileak.exe is excellent.

    For all others leak types, take a look at Numega Bounds Checker (visit www.compuware.com and follow the evaluation links. You cannot download an eval version directly, you have to phone the company to request an eval version. They will give you one though. Another good product you can evaluate is Rational Rose Purify.


    Jase

    http://www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    Last edited by jase jennings; July 22nd, 2003 at 04:37 AM.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  3. #3
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    Re: Finding or detecting memory leaks?

    1 point for my life story ? There's no pleasing some people


    Jase

    http://www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  4. #4
    Join Date
    Apr 1999
    Posts
    123

    gdileak.exe

    Do you have a link for this application? It does not turn up in a search on the internet or on Microsoft. Also, the Microsoft link is no longer valid.

  5. #5
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Hi Bob

    I'm sorry if Microsoft have broken their links since I made this post, searching for appropriate terms in the knowledge base and technical articles should find similar content.

    I will attach gditest.exe to this thread when i get home later tonight, it's a very small exe. It's a useful tool, it shows you all the gdi handles in use by the system in realtime, so you can see when testing your application if they are growing out of hand due to leaks etc ...

    Jase

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

  7. #7
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520
    Here it is ..
    Attached Files Attached Files

    Jase

    www.slideshowdesktop.com
    View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows.
    ...

  8. #8
    Join Date
    Jul 2001
    Location
    Germany
    Posts
    220
    a very good debugger to find memory leaks is BoundsChecker (now distributed by Compuware).
    You can download a trial version.

    After several days searching for a weird problem, I installed BC, and very soon I could locate the problem.
    So, my boss was easily convinced to spend the money ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured