【发布时间】:2017-03-16 01:18:47
【问题描述】:
VLD 在以下代码中检测到内存泄漏:
typedef Poco::SharedPtr<double> DoublePtr;
class A {
public:
DoublePtr a;
};
class B:public A {
public:
DoublePtr b;
};
class C : public B
{
public:
DoublePtr c;
};
typedef Poco::SharedPtr<A> APtr;
typedef Poco::SharedPtr<B> BPtr;
typedef Poco::SharedPtr<C> CPtr;
class Test {
public:
Test() {
CPtr c1 = new C();
a_list.push_back(c1);
}
std::list<APtr> a_list;
};
int main(int argc, char *argv[])
{
Test test;
}
但是当使用 std::shared_ptr 或 boost::shared_ptr 时可以。 而且,如果我添加 'virtual ~A(){}',Poco::SharedPtr 也可以!
是 Poco::SharedPtr 的 bug 吗??
【问题讨论】:
-
Poco::SharedPtr是否键入擦除删除器?否则,由于非虚拟基础析构函数,您的代码具有 UB。
标签: c++ memory-leaks poco stdlist