我正在使用visual studio 2010和boost库。我试图在主函数退出后使用_CrtDumpMemoryLeaks查找内存泄漏。我非常确定boost_log_trivial不会泄漏内存。如何避免这种误报?
源代码:
#define _CRTDBG_MAP_ALLOC
#include <boost/log/trivial.hpp>
#include <iostream>
#include <stdlib.h>
#include <crtdbg.h>
_CrtMemState initial_state;
_CrtMemState final_state;
_CrtMemState state_diff;
using namespace std;
struct AtExit
{
~AtExit() {
_CrtMemCheckpoint( &final_state );
if ( _CrtMemDifference( &state_diff, &initial_state, &final_state) )
{
_CrtMemDumpStatistics( &state_diff );
_CrtDumpMemoryLeaks();
}
}
} doAtExit;
void leak_causing_fn()
{
BOOST_LOG_TRIVIAL(error) << "Module: ";
}
int main()
{
_CrtMemCheckpoint( &initial_state );
leak_causing_fn();
return 0;
}
输出:
0 bytes in 0 Free Blocks.
1724 bytes in 47 Normal Blocks.
4164 bytes in 5 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 5716 bytes.
Total allocations: 6832 bytes.
Detected memory leaks!
Dumping objects ->
{359} normal block at 0x00AD9B90, 4 bytes long.
Data: < < > 90 3C 00 00
{349} normal block at 0x00AD98D0, 176 bytes long.
Data: < D ) > 00 00 00 00 CD CD CD CD 44 E5 29 0F E8 96 AD 00
.....