RE: [boost] enabling automatic memory leak detection with VC

I also used this idom, it is very nice. One thing to watch out for is 'false positives' from other global/static objects that do mallocs. leak_reporter leak_reporter::instance; std::string i_will_trigger_leak_report; I am not aware of any automatic way to avoid this. m
-----Original Message----- From: Robert Ramey [mailto:ramey@rrsd.com] Sent: Thursday, May 20, 2004 2:06 PM To: boost@lists.boost.org Subject: [boost] enabling automatic memory leak detection with VC
While investigating shared_ptr serialization, I've come upon the VC method used for detecting memory leaks. I had previously used it as part of MFC and found it very helpful. By including the following at the beginning of one's test program:
#define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h>
struct leak_reporter { static leak_reporter instance; leak_reporter(){ _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); } ~leak_reporter(){ // _CrtDumpMemoryLeaks(); // replaced by the above } }; leak_reporter leak_reporter::instance;
The program displays the following in the output window while running under the VC IDE:
Detected memory leaks! Dumping objects -> c:\program files\microsoft visual studio .net 2003\vc7\include\crtdbg.h(689) : {663} normal block at 0x00325480, 24 bytes long. Data: < ,W > C4 2C 57 00 00 00 00 00 FF FF FF FF 00 00 00 00 c:\program files\microsoft visual studio .net 2003\vc7\include\crtdbg.h(689) : {393} normal block at 0x003261F0, 24 bytes long. Data: < ,W > 94 2C 57 00 00 00 00 00 FF FF FF FF 00 00 00 00 Object dump complete.
The sequential number (663 and 393 in this example) can be used to trap the debugger at the original allocation when the test is run the next time.
Is this not a worthy idea to be included in the test system - at least for VC? In this way we would get a report of memory leaks every time we ran a test.
Robert Ramey
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.

"Max Khesin" <MKhesin@liquidnet.com> skrev i meddelandet news:4B6FB7F60D37D41188C300B0D022E0C0029F42D9@exchange.lnholdings.com...
I also used this idom, it is very nice. One thing to watch out for is 'false positives' from other global/static objects that do mallocs.
leak_reporter leak_reporter::instance; std::string i_will_trigger_leak_report;
Another well known problem is that std::cin and std::cout will have to keep its locale info around until everything else has been shut down. Bo Persson
participants (2)
-
Bo Persson
-
Max Khesin