Results 1 to 4 of 4

Thread: Memory Leaks

  1. #1

    Thread Starter
    Addicted Member HairyDave's Avatar
    Join Date
    Aug 2002
    Location
    Er...I can't remember.
    Posts
    196

    Memory Leaks

    What do people here use when they think they have a memory leak? Any useful tools in VC++ that do anything useful?

    Thanks

    HD

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I have found this to be helpful:

    PHP Code:
    #include <crtdbg.h>

    #define CONSTRUCTOR_TRACE
    #define FUNCTION_TRACE

    #ifdef _DEBUG
    #define DBG_NEW new(_NORMAL_BLOCK,__FILE__, __LINE__)
    #endif

    //Put in your main
    //Setup Debug In .cpp
    #ifndef NDEBUG

        
    int flag _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Get current flag

        
    flag |= _CRTDBG_LEAK_CHECK_DF// Turn on leak-checking bit

        
    _CrtSetDbgFlag(flag); // Set flag to the new value

    #endif 
    It will dump leaks to the debug window
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    I go through my code another time and tighten up the loose ends...
    VS.NET 2003

    Need to email me?

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Re: Memory Leaks

    Originally posted by HairyDave
    What do people here use when they think they have a memory leak? Any useful tools in VC++ that do anything useful?

    Thanks

    HD
    Why don't you search in the MSDN library on your PC?

    Put these code before other include headers
    Code:
    #define _CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>
    You need to have these too, but usually MFC wizard will put there for you, unless you handcoded the cpp yourself.

    Code:
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    And put this in the destructor of your class

    Code:
    _CrtDumpMemoryLeaks();
    Compile your app in debug mode and do debug->Go

    If you want to know more in detail, search in the MSDN.

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