使用 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.
我尝试设置预处理器定义
_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
没有行号。我还尝试使用 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;
}
但也没有成功。这怎么能做到呢?
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_function, argc, argv );
_CrtDumpMemoryLeaks();
return res;
}
But also without any success. How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Boost.Test 您可以使用 --detect_memory_leaks="allocation number"
Using Boost.Test you can use --detect_memory_leaks="allocation number"
在MSVC中,您可以在代码中将断点设置为分配号1466:
或者在Watch窗口中,您可以在应用程序启动后添加
_crtBreakAlloc
和值1466(当然,您需要在主程序中设置断点)功能)。 有关 MSDN 的更多详细信息In MSVC you can set a breakpoint to the allocation number 1466, in the code:
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尝试使用调试器!例如,在 deleaker 的帮助下可以选择堆栈来查看内存分配的位置
Try to use the debugger! For example, with help of deleaker can select the stack to see where memory was allocated