【发布时间】:2010-12-11 07:31:54
【问题描述】:
用 valgrind 运行我的回归测试我有这样的报告:
==20341== 1 个块中的 256 个字节在 919 的丢失记录 915 中间接丢失 ==20341== at 0x4A0661C: operator new(unsigned long) (vg_replace_malloc.c:220) ==20341== by 0x7F366FA: std::vector<:test std::allocator> >::_M_insert_aux(__gnu_cxx::__normal_iterator<:test std:: std::allocator> > >, CppUnit::Test* const&) (new_allocator.h:88) ==20341== by 0x7F36496: CppUnit::TestSuite::addTest(CppUnit::Test*) (stl_vector.h:610) ==20341== 0x585B80:TestVectorAlgebra::addTestsToSuite(CppUnit::TestSuiteBuilderContextBase&) (testvectoralgebra.h:30) ==20341== by 0x586719: TestVectorAlgebra::suite() (testvectoralgebra.h:42) ==20341== 0x5948C4:CppUnit::TestSuiteFactory我猜这是因为添加到 Suite 的测试在主程序结束之前没有被删除。
这是我注册测试的方式:
CppUnit::TextTestRunner::TestRunner runner;
// Get the top level suite from the registry
CppUnit::Test* myTest =
CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
runner.addTest( myTest->findTest("TestVectorAlgebra") );
如何取消注册这些测试?
【问题讨论】:
-
我也用一些 Windows 内存分析器诊断出这个泄漏。我发现 CppUnit 被过度设计了。换句话说,这是一堆垃圾。