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
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?
It have!!!!
To check it, I write this code:
char* fgh=new char[10];
But it will not be shown.
Ralf
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.
Can you help?!
Thx
Ralf
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?
Hallo Alex,
thx. The problem were C++ new.
I found this and it helps:
http://social.msdn.microsoft.com/for...-8a73575dfb10/
Ralf
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
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
Re: Show memory leaks in dll?
Ok .. But while using debug mode , I have not seen this information. Can you guide me more ?
Re: Show memory leaks in dll?
maybe there are no memory leaks?
Then there is no report!
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
Re: Show memory leaks in dll?
e.g.
char* zz=new char[10]; // without releasing later!
somewhere in the code.
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
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?
Re: Show memory leaks in dll?
Hello Ovidiu,
the DLLs are not developed by me. I have to use it and find the bugs!!!!!
Very bad....
But do not think about further. My problem is solved for the moment.
Ralf
Re: Show memory leaks in dll?
Quote:
Originally Posted by
Ralf Schneider
Hello Ovidiu,
[...]
But do not think about further. My problem is solved for the moment.
Ralf
Hello Ralf,
Congratulations, that's great!
Can you share with us how did you solve the problem?
Re: Show memory leaks in dll?