将 SharedPtr 与 std::list 一起使用时内存泄漏!错误
Memory Leak when using SharedPtr with std::list! Bug?
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 的错误吗?
A
需要有一个虚拟析构函数;如果没有,则通过A
指针删除B
或C
对象会导致未定义的行为。未定义的行为可能包括内存泄漏。
相关文章:
- 从构造函数抛出异常时如何克服内存泄漏
- malloc() 可能出现内存泄漏
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 尽管遵循了规则,内存泄漏在哪里
- 为什么调用堆栈数组会导致内存泄漏
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 使用模板类的自定义列表类型中的内存泄漏
- 为什么以下C++代码中存在内存泄漏?
- OpenCV 我应该使用智能指针来防止内存泄漏吗?
- 我是否生成线程并导致内存泄漏?
- 多线程程序中出现意外的内存泄漏
- 为什么此函数会导致内存泄漏?
- 在 C++ 库中使用cythonized python时内存泄漏
- 需要帮助查找内存泄漏
- 瓦尔格林德的内存泄漏使用新的
- 无法找出我的代码中的内存泄漏
- C++ 结构内部的unordered_map会导致内存泄漏问题吗?
- 可视化 使用 VS Code 查找C++应用程序中的内存泄漏
- Shared_ptr双链接列表内存泄漏
- C++ 在类中使用常量引用文本时 O2 内存泄漏