If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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.

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?

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.

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?

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?

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?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.