CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Jul 2001
    Posts
    306

    Show memory leaks in dll?

    Hello,

    when ending my app in the debugger, memory leaks will be shown like this:
    Detected memory leaks!
    Dumping objects ->
    C:\PROGRAM FILES\VISUAL STUDIO\MyProjects\leaktest\leaktest.cpp(20) : {18}
    normal block at 0x00780E80, 64 bytes long.
    Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
    Object dump complete.

    How can I tell Visual c++ also to show me the memory leaks in a called dll?

    thx
    Ralf

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Show memory leaks in dll?

    VC++ program prints memory leaks by calling _CrtDumpMemoryLeaks just before the program is closed. Memory leaks dump includes all libraries in the process. In your case, if executable uses dll, this dll doesn't have memory leaks.

  3. #3
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    It have!!!!
    To check it, I write this code:
    char* fgh=new char[10];
    But it will not be shown.

    Ralf

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Show memory leaks in dll?

    You need to be more specific. Is this MFC application or not? Do you request memory leaks dump? Do you redefine new to DEBUG_NEW? Where is the code that creates memory leaks in both your posts? What is Dll type, how it is loaded by main executable?

  5. #5
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    Hello Alex,

    thx. I am one step further!
    The calling app is mfc. The dll non-mfc.
    Now, I included
    #define _CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>
    in the header files of the dll.

    This leads to the following:
    1) when I call _CrtDumpMemoryLeaks() I get a dump.
    But it says for every memory block that it is created in crtdbg.h (552), not the actual line of code that calls "new".
    2) there is no automatic dump of the dll-leaks when the app ends.

    Can you help?!

    Thx
    Ralf

  6. #6
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Show memory leaks in dll?

    You don't need to call _CrtDumpMemoryLeaks. MFC calls this function when all user libraries are unloaded. _CrtDumpMemoryLeaks just prints all undeleted allocations. So, if you call this function, it just prints everything that is allocated for now.
    _CRTDBG_MAP_ALLOC is used for malloc tracking, not for C++ new operations. It is not related here.
    So, if the whole project is MFC, every C++ allocation which is not released, must be printed in the end. Are you sure that allocation line in Dll is executed and the pointer is not released?
    Try to create minimal MFC exe and minimal Dll with default parameters. Exe depends on this Dll. Call Dll function which makes allocation. It should work. If it doesn't work in your case, there must be something else. Maybe your Dll uses it own heap?

  7. #7
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    Hallo Alex,

    thx. The problem were C++ new.
    I found this and it helps:
    http://social.msdn.microsoft.com/for...-8a73575dfb10/

    Ralf

  8. #8
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Re: Show memory leaks in dll?

    Hi ,

    Pl tell me how to use this function with MFC.

    When and Where should I call that and how Can I see the output ?

    Thanks a lot

  9. #9
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    Hello,

    do you refer to my link?
    In MFC you do not need it. The leaks will be shown at the end of the programme in debug mode with VC++ automatically.

    Ralf

  10. #10
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Re: Show memory leaks in dll?

    Ok .. But while using debug mode , I have not seen this information. Can you guide me more ?

  11. #11
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    maybe there are no memory leaks?
    Then there is no report!

  12. #12
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Show memory leaks in dll?

    Hi ,

    Pl tell me how to make memory leaks with MFC.

    When and Where should I call that and how Can I see the output ?

    Thanks a lot

  13. #13
    Join Date
    Jul 2001
    Posts
    306

    Re: Show memory leaks in dll?

    e.g.

    char* zz=new char[10]; // without releasing later!

    somewhere in the code.

  14. #14
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Show memory leaks in dll?

    If the DLL uses MFC (it's a MFC-extension DLL or regular DLL using MFC) and you have source files, then for detecting the source of memory leaks is enough to have defined DEBUG_NEW in each implemetation file (as Alex suggested before).
    Have a look at this short article:
    How to detect memory leaks in MFC?

    [Later edit]
    I've added that to Codeguru FAQ's:
    http://forums.codeguru.com/showthread.php?531831
    Last edited by ovidiucucu; December 26th, 2012 at 04:44 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  15. #15
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Show memory leaks in dll?

    Now, if your DLL doesn't use MFC, all I've said isn't possible because MFC uses it's own allocator (basically by overloading operators new and delete).
    So, I have a little question: is any good reason for you to develop DLLs which do not use MFC in an MFC-based project, other than for generating memory allocation headaches?
    Last edited by ovidiucucu; December 26th, 2012 at 05:51 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Page 1 of 2 12 LastLast

Tags for this Thread

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