Visual Leak Detector在以下代码中观察到内存泄漏(次要40个字节)..
...
void simulatememoryleak(){
boost::asio::io_service m_IOService;
boost::asio::serial_port m_SerialPort( m_IOService, "COM21" );;
m_SerialPort.cancel();
m_SerialPort.close();
m_IOService.stop();
m_IOService.reset();
}
..
有谁能说明这是为什么?
我还向VLD发布了问题并推动了社区..
答案 0 :(得分:0)
在我的linux机器上,只有在没有打开串口的权限时它才会泄漏(在这种情况下,它会因异常而中止)。
这是工作运行的一个valgrind¹:
$ sudo valgrind --leak-check=full ./test
==21281== Memcheck, a memory error detector
==21281== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==21281== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==21281== Command: ./test
==21281==
==21281==
==21281== HEAP SUMMARY:
==21281== in use at exit: 0 bytes in 0 blocks
==21281== total heap usage: 10 allocs, 10 frees, 851 bytes allocated
==21281==
==21281== All heap blocks were freed -- no leaks are possible
==21281==
==21281== For counts of detected and suppressed errors, rerun with: -v
==21281== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
如果没有以root用户身份运行,我会
==21286== possibly lost: 331 bytes in 4 blocks
==21286== still reachable: 664 bytes in 8 blocks
¹使用/dev/ttyS0
或类似的