CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Memory leak detection

  1. #1
    Join Date
    Aug 2002
    Posts
    714

    Memory leak detection

    Hi,
    I am developing an application which contains of a binary executable and couple of DLLs.

    I do see that in some scenarios I have memory leaks. Since they are not good I want to fix them.

    Googling pointed me to this. What I'd like to know is how to define this when the application have multiple DLLs.

    1. Should I define _CRTDBG_MAP_ALLOC, only once in my main application start up or I need to define it on every DLL loading?
    2. The same with the:

    Code:
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    ?

    The application is a GUI one developed with wxWidgets, so it has 1 entry and 1 exit points.

    Thank you.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,358

    Re: Memory leak detection

    The following comment from the link leads me to believe _CRTDBG_ALLOC__MEM_DF only needs to be defined once.

    "By default, _CrtDumpMemoryLeaks outputs the memory-leak report to the Debug pane of the Output window. If you use a library, the library might reset the output to another location."

    If you are still in doubt, you can test for it by creating a memory leak in one of your DLLs and see if it spews to the output window.

  3. #3
    Join Date
    Aug 2002
    Posts
    714

    Re: Memory leak detection

    Hi,
    It is not a matter of reporting the leak - I see it present.
    What I'm after is the place where allocation occurs.

    I tried to run VLD, but got a crash on the application start-up. So thought of trying with the MSVC way.

    I just tried to put those 3 lines in the application constructor but didn't see any reports of the line numbers for where allocation occur.

    I will try to place them in the every DLL initialization routine.

    Thank you.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,358

    Re: Memory leak detection

    Create a test solution with exe and dll projects, introduce leaks, and get it working there.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)