使用boost :: test检测内存泄漏

sch*_*tbi 6 c++ memory-leaks boost-test

我尝试启用msvc内存泄漏检测与行号,就像我在这里找到的这个片段:

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.
Run Code Online (Sandbox Code Playgroud)

我试着设置预处理器定义

_CRTDBG_MAP_ALLOC

在项目属性中手动但我只得到这个:

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
Run Code Online (Sandbox Code Playgroud)

没有行号.我还试图通过使用BOOST_TEST_NO_MAIN手动定义main并自行转储,如下所示:

int main( int argc, char* argv[] )
{
    int res = ::boost::unit_test::unit_test_main( &init_function, argc, argv );  
    _CrtDumpMemoryLeaks();
    return res;
}
Run Code Online (Sandbox Code Playgroud)

但也没有任何成功.如何才能做到这一点?

Gen*_*tal 5

使用Boost.Test,您可以使用--detect_memory_leaks ="分配编号"