【发布时间】:2016-09-07 06:29:10
【问题描述】:
我有一个
priority_queue<node*, std::vector<node*>, CompareNodes> heap;
假设节点包括:
class node {
public:
int value;
int key;
int order = 1000000;
};
完成优先队列后如何释放内存? 我的方法似乎不起作用:
while (heap.top()) {
node * t = heap.top();
heap.pop();
delete t;
}
【问题讨论】:
-
什么告诉你它不起作用?此外,如果没有 NULL 元素,这似乎总是会抛出。
-
将问题描述为“似乎不起作用”是没有帮助的。 究竟出了什么问题?
-
请发帖minimal reproducible example(stackoverflow.com/help/mcve)。
-
@DavidSchwartz 我的意思是程序触发断点并关闭
-
您的代码中没有任何内容表明您必须释放任何内存。最好发minimal reproducible example。
标签: c++ pointers memory-leaks free