Deque指针内存泄漏
Deque Pointer Memory Leak
我有一个结构,在其中我使用了std::deque
class VariantWrapper;
typedef _STL_NAMESPACE_::deque<VariantWrapper> VariantQueue;
struct AttributeValueWrapper
{
AttributeValueWrapper() : bAttributeIsArray(false)
{
pVariantQueue = new VariantQueue;
if(!pVariantQueue)
throw std::bad_alloc();
}
AttributeValueWrapper(const AttributeValueWrapper& a)
{
pVariantQueue = a.TakeOwner();
bAttributeIsArray = a.bAttributeIsArray;
}
AttributeValueWrapper& operator=(AttributeValueWrapper& r)
{
throw std::bad_exception("equal operator not supported in AttributeValueWrapper");
}
VariantQueue* TakeOwner() const
{
VariantQueue *p = pVariantQueue;
pVariantQueue = NULL;
return p;
}
~AttributeValueWrapper()
{
if (pVariantQueue)
{
delete pVariantQueue;
}
}
bool bAttributeIsArray;
mutable VariantQueue *pVariantQueue;};
主要方法:
int main()
{
AttributeValueWrapper attrib;
}
我在Dr Memory下运行这段代码(这只是一段代码,项目相当大),Dr Memory在默认构造函数内的pVariantQueue = new VariantQueue
作为:
错误#46:LEAK 8个直接字节+324个间接字节替换操作员新d: \drmemory_package\common\alloc_replace.c(2899):std::_Allocate<>:0std::分配器<>::分配:0std::_Wrap_alloc<>::分配:0std::_Deque_alloc<>::_分配代理(_P):0std::_Deque_alloc<>::_Deque_alloc<>:0std::deque<>::deque<>:0AttributeValueWrapper::AttributeValueWraper
请分享你对这个问题的看法。
我也尝试过使用std::unique_ptr
,但在同一行(同一点):上仍然出现了相同的内存泄漏
struct AttributeValueWrapper
{
AttributeValueWrapper() : bAttributeIsArray(false)
{
pVariantQueue = std::make_unique<VariantQueue>(new VariantQueue);
if(!pVariantQueue)
throw std::bad_alloc();
}
AttributeValueWrapper(const AttributeValueWrapper& a)
{
pVariantQueue = a.TakeOwner();
bAttributeIsArray = a.bAttributeIsArray;
}
AttributeValueWrapper& operator=(AttributeValueWrapper& r)
{
throw std::bad_exception("equal operator not supported in AttributeValueWrapper");
}
std::unique_ptr<VariantQueue> TakeOwner() const
{
std::unique_ptr<VariantQueue> p = std::move(pVariantQueue);
pVariantQueue = NULL;
return p;
}
~AttributeValueWrapper()
{
}
bool bAttributeIsArray;
mutable std::unique_ptr<VariantQueue> pVariantQueue;
};
现在内存泄漏
pVariantQueue = std::make_unique<VariantQueue>(new VariantQueue);
Vinay
您的内存泄漏很可能在析构函数中找到。当队列消失时,队列中的对象会发生什么?
相关文章:
- C++功能泄漏内存,我是C++新手,不确定如何解决
- 我的堆栈弹出式磁带的实现是否泄漏内存?
- 将 c++ 向量转换为字符 ** 而不会泄漏内存
- 析构函数 C++ 使泄漏内存
- 构造函数对象赋值是否泄漏内存
- corba :: orb_init泄漏内存
- Gmock泄漏内存
- 如何在不泄漏内存的情况下删除链接列表
- Visual C ODBC关闭记录集泄漏内存
- 为什么泄漏内存比在动态数组上执行 delete[] 慢
- OpenGL正在泄漏内存.哪个对象未释放
- 可以std ::退出泄漏内存
- uiautomation findall泄漏内存
- 为什么在此OpenCL代码中泄漏内存,为什么要泄漏内存
- pthread在完成后会泄漏内存
- win32 标准::线程泄漏内存
- 返回指向同一变量的指针是否会泄漏内存
- 使用clectType(new any_type())可能会泄漏内存泄漏
- Windows开发:如何确定我的应用程序是否正在泄漏内存
- WinHttp打开泄漏内存