在指向std :: list的指针上使用delete? [英] Using delete on pointer to std::list?

查看:211
本文介绍了在指向std :: list的指针上使用delete?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,有一个指向std::list对象的指针,它的分配方式如下.

d_list_p = new std::list<some_type*>();

然后在我的程序中稍后将其删除.

d_list_p->clear();
delete d_list_p;

由于某种原因,我在delete语句上触发了Windows断点.如果我在delete语句处中断,则会看到该列表存在且大小为0.此外,我从不向该列表中添加引发错误的案例元素(我认为).

正在使用VS2005的MS VC ++编译器来编译代码.

该错误消息显示Windows触发了一个断点,指示内存损坏.堆栈跟踪显示以下内容.

ntdll.dll!DbgBreakPoint()   
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x6735 bytes  
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x6b72 bytes  
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x7d5a bytes  
ntdll.dll!LdrAlternateResourcesEnabled()  + 0x33bd bytes    
ntdll.dll!RtlpUnWaitCriticalSection()  + 0x65b bytes    
msvcr80.dll!free()  + 0xcd bytes    
FM_Access_Library_NET.dll!std::list<FM_Access_Library::Logger_Callbacks *,std::allocator<FM_Access_Library::Logger_Callbacks *> >::`scalar deleting destructor'()  + 0x20 bytes C++

可能值得一提的是,此delete语句是内置在.NET DLL中的C ++代码中,因此该程序以混合模式运行.

解决方案

d_list_p是类的成员吗?并且,该类是否遵守三人制?

如果没有,那么d_list_p(的副本)可能已经被删除.

In my program I have a pointer to a std::list object, it is allocated like so.

d_list_p = new std::list<some_type*>();

Then later in my program I delete it like so.

d_list_p->clear();
delete d_list_p;

For some reason I'm getting a Windows breakpoint triggered on the delete statement. If I break at the delete statement I see that the list exists and has a size of 0. Also, I never add an element to the list for the case that throws an error (I think).

The code is being compiled with the MS VC++ compiler for VS2005.

The error message says Windows triggered a breakpoint indicating memory corruption. The stack trace says the following.

ntdll.dll!DbgBreakPoint()   
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x6735 bytes  
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x6b72 bytes  
ntdll.dll!RtlpNtMakeTemporaryKey()  + 0x7d5a bytes  
ntdll.dll!LdrAlternateResourcesEnabled()  + 0x33bd bytes    
ntdll.dll!RtlpUnWaitCriticalSection()  + 0x65b bytes    
msvcr80.dll!free()  + 0xcd bytes    
FM_Access_Library_NET.dll!std::list<FM_Access_Library::Logger_Callbacks *,std::allocator<FM_Access_Library::Logger_Callbacks *> >::`scalar deleting destructor'()  + 0x20 bytes C++

It is probably worth mentioning that this delete statement is in C++ code that is being built into a .NET DLL, so the program is running in mixed-mode.

解决方案

Is d_list_p a member of a class? And, does that class observe the Rule of Three?

If not, then (a copy of) d_list_p may have already been deleted.

这篇关于在指向std :: list的指针上使用delete?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆