Memory leak detection with boost::test
I try to enable msvc memory leak detection with line number like this snippet I found here:
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.
I tried to set the preprocessor define
_CRTDBG_MAP_ALLOC
manually in the project properties but I only get this:
Dumping objects ->
{1466} normal block at 0x00BD4DD0, 40 bytes long.
Data: <(o; ; (o; 1 > 28 6F 3B 00 90 A9 3B 00 28 6F 3B 00 00 D6 31 10
without line numbers. I also tried to manually define main by using BOOST_TEST_NO_MAIN and dump by myself like this:
int main( int argc, char* argv[] )
{
int res = ::boost::unit_test::unit_test_main( &init_开发者_如何学Pythonfunction, argc, argv );
_CrtDumpMemoryLeaks();
return res;
}
But also without any success. How can this be done?
Using Boost.Test you can use --detect_memory_leaks="allocation number"
In MSVC you can set a breakpoint to the allocation number 1466, in the code:
_crtBreakAlloc = 1466
or in the Watch window you can add _crtBreakAlloc
and value 1466 once the application started (of course you need a breakpoint in the main function). More details on MSDN
Try to use the debugger! For example, with help of deleaker can select the stack to see where memory was allocated
精彩评论