该内存会被正确释放吗?
我有一个对指针让我们假设 std::pair< A*, B* >* 指针对。我为它分配了内存,并在使用该对后我称之为删除指针对。
它还会调用删除 A 和删除 B 并完全释放内存吗?
如果我只调用delete A和delete B但没有删除指针对那么这是内存泄漏吗?
I have a pair pointer let us suppose std::pair< A*, B* >* pointerpair. I allocated it memory and after using the pair i call delete pointerpair.
Will it also call delete A and delete B and will be freeing the memory completely ?
if i only call delete A and delete B but no delete pointerpair then is it a memory leak ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不会
。但是,在STL和Boost中,有一类叫做智能指针的类,它可以自动删除其中存储了指针的对象。然而,在这些智能指针类之外,存储在 STL / Boost 容器中的任何原始指针都被简单地视为指针。例如,您可以定义一组指向字符串的原始指针。该集合将使用指针值排序,而不是字符串的字典顺序(除非您提供比较函子)。
No.
However, in STL and Boost, there is a family of classes called smart pointers, which can automatically delete the objects whose pointers are stored in them. However, outside those smart pointer classes, any raw pointers stored in STL / Boost containers are simply treated as pointers. For example, you can define a set of raw pointers to strings. This set will be sorted using the pointer values, not the lexicographical order of the strings (unless you supply your comparison functor).
不,它不会自动完成。您必须明确删除它。
No. It won't do it automatically. You have to delete it explicitly.