Memmory Leak Tools
Actually Simon, that code in the other thread gives me numerous compile-time errors when I try it. The source tags mangled your post in that thread however, so I might have entered it incorrectly or missed something. Any chance you could repost the exact syntax of what comes after the ''#define _CRTDBG_MAP_ALLOC'' line (which MSDN implies should be enough to show the file/line info on its own, but doesn''t)?
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Kylotan:
Compiles fine for me as posted (MSVC 6) - I just created a new Win32 application, copied in the code from the post, sorted out the newlines and hit F7 - all fine.
What compile errors are you getting ?
Including the crtdbg.h header is essential, as are the 2 #defines which replace the "new" operator with a macro which calls the special CRT debugging version of the new operator.
All #''s need to start on a new line
The _CrtSetDbgFlag calls are necessary to enable the reports at program exit.
BTW: The reason just enabling the _CRTDBG_MAP_ALLOC doesn''t work is due to an oversight at MS - that the __LINE__ and __FILE__ are converted to strings by the preprocessor rather than the compiler! This means that the __LINE__ and __FILE__ in crtdbg only give you the line number in that file - doing the overloading/overriding in a macro means that the __LINE__ and __FILE__ are resolved by the preprocessor on a per use basis.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
Compiles fine for me as posted (MSVC 6) - I just created a new Win32 application, copied in the code from the post, sorted out the newlines and hit F7 - all fine.
What compile errors are you getting ?
Including the crtdbg.h header is essential, as are the 2 #defines which replace the "new" operator with a macro which calls the special CRT debugging version of the new operator.
All #''s need to start on a new line
The _CrtSetDbgFlag calls are necessary to enable the reports at program exit.
BTW: The reason just enabling the _CRTDBG_MAP_ALLOC doesn''t work is due to an oversight at MS - that the __LINE__ and __FILE__ are converted to strings by the preprocessor rather than the compiler! This means that the __LINE__ and __FILE__ in crtdbg only give you the line number in that file - doing the overloading/overriding in a macro means that the __LINE__ and __FILE__ are resolved by the preprocessor on a per use basis.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
This is the code I have in the first header file included by my .cpp file:
Which is pretty much copy/pasted from the other thread. I get these errors:
stdlib.h(281) : error C2059: syntax error : 'constant'
stdlib.h(281) : error C2733: second C linkage of overloaded function '_calloc_dbg' not allowed
stdlib.h(281) : see declaration of '_calloc_dbg'
stdlib.h(283) : error C2059: syntax error : 'constant'
stdlib.h(283) : error C2733: second C linkage of overloaded function '_free_dbg' not allowed
stdlib.h(283) : see declaration of '_free_dbg'
stdlib.h(298) : error C2059: syntax error : 'constant'
stdlib.h(298) : error C2733: second C linkage of overloaded function '_malloc_dbg' not allowed
stdlib.h(298) : see declaration of '_malloc_dbg'
etc etc etc...
Looks like it's getting done twice... but the code I posted above is the first thing I #include, so it should affect everything... right?
The code in the article Magmai linked to works fine, by the way: just a slightly different syntax.
I'm using MSVC6.
PS. Don't worry too much about this: it occured to me that I would need to add this individually to every single file in my project, which is pretty unviable at the moment. Why is there no equivalent to __file__ which evaluates to the file you're compiling, rather than the file you actually typed it into? *sighs*
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Edited by - Kylotan on January 19, 2002 8:13:50 PM
Edited by - Kylotan on January 19, 2002 8:21:12 PM
#ifdef _DEBUG#define _CRTDBG_MAP_ALLOC#include "crtdbg.h"#define DEBUG_NEW_FN new( _NORMAL_BLOCK, __FILE__, __LINE__)#define new DEBUG_NEW_FN
Which is pretty much copy/pasted from the other thread. I get these errors:
stdlib.h(281) : error C2059: syntax error : 'constant'
stdlib.h(281) : error C2733: second C linkage of overloaded function '_calloc_dbg' not allowed
stdlib.h(281) : see declaration of '_calloc_dbg'
stdlib.h(283) : error C2059: syntax error : 'constant'
stdlib.h(283) : error C2733: second C linkage of overloaded function '_free_dbg' not allowed
stdlib.h(283) : see declaration of '_free_dbg'
stdlib.h(298) : error C2059: syntax error : 'constant'
stdlib.h(298) : error C2733: second C linkage of overloaded function '_malloc_dbg' not allowed
stdlib.h(298) : see declaration of '_malloc_dbg'
etc etc etc...
Looks like it's getting done twice... but the code I posted above is the first thing I #include, so it should affect everything... right?
The code in the article Magmai linked to works fine, by the way: just a slightly different syntax.
I'm using MSVC6.
PS. Don't worry too much about this: it occured to me that I would need to add this individually to every single file in my project, which is pretty unviable at the moment. Why is there no equivalent to __file__ which evaluates to the file you're compiling, rather than the file you actually typed it into? *sighs*
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Edited by - Kylotan on January 19, 2002 8:13:50 PM
Edited by - Kylotan on January 19, 2002 8:21:12 PM
Dunno...
always works for me - no matter what abuse I try to put it through. Also ok worked for the other 3 programmers on our current project.
Have you tried it in a totally fresh, project workspace rather than an existing project ?
Also since that particular example I posted was intended to all be in a .cpp file, you should probably add an inclusion guard to the header file.
Other things it could be:
- other code, elsewhere doing the same thing.
- other code with a different memory manager clashing with the CRT one.
- overloaded operator new somewhere which doesn''t support the extra parameters.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
always works for me - no matter what abuse I try to put it through. Also ok worked for the other 3 programmers on our current project.
Have you tried it in a totally fresh, project workspace rather than an existing project ?
Also since that particular example I posted was intended to all be in a .cpp file, you should probably add an inclusion guard to the header file.
Other things it could be:
- other code, elsewhere doing the same thing.
- other code with a different memory manager clashing with the CRT one.
- overloaded operator new somewhere which doesn''t support the extra parameters.
--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com
I think I found it - certain STL files include the "new" header which contains the following:
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
// new AND delete DECLARATIONSvoid __cdecl operator delete(void *) _THROW0();void *__cdecl operator new(size_t) _THROW1(std::bad_alloc);void *__cdecl operator new(size_t, const std::nothrow_t&) _THROW0();
along with another overloaded new elsewhere. Maybe they are conflicting. [ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:Original post by Magmai Kai Holmlor
Article on finding Memory Leaks
Hate to bump an old thread, but I found that link EXTREMELY useful.
I read the article, I implemented the class and started it in my main class, started the program in debug mode to see the results.
I have results as the page said BUT they only report to the Header of the debug class. I cant find where the memory leaks are that way.
Is it because I need to insert the debug class header in all my classes or some such?
I have results as the page said BUT they only report to the Header of the debug class. I cant find where the memory leaks are that way.
Is it because I need to insert the debug class header in all my classes or some such?
Also ...
what program is good for finding what is leaking under LINUX?
and in C++ also.
url links anyone?
-PK-
what program is good for finding what is leaking under LINUX?
and in C++ also.
url links anyone?
-PK-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement