代码: 全选
int *a=new int;
int *b=new;
a=b;
代码: 全选
int *a=new int;
int *b=new;
a=b;
这就是臭名昭著的内存泄漏阿。rob2468 写了:a和b开始都申请了堆空间,然后又执行了a=b的操作,a,b指向同一片空间,那么我delete b;就把b的空间释放了,那么a此时也不能再使用了,第一行申请的地址怎么释放呢代码: 全选
int *a=new int; int *b=new; a=b;
代码: 全选
Type MinHeap<Type>::[color=#FF4000]DeleteTop()[/color]
{
if(IsEmpty())
{
cout<<"堆已空"<<endl;
exit(1);
}
[color=#FF0000]Type temp=heapArr[0];[/color]
heapArr[0]=heapArr[heapCurrentSize-1];//堆末元素上移到堆顶
heapCurrentSize--;
FilterDown(0);
[color=#FF4000]return temp;[/color]
}
代码: 全选
firstChild=new HuaffmanTreeNode;
secondChild=new HuaffmanTreeNode;
*firstChild=hp.DeleteTop();
*secondChild=hp.DeleteTop();
代码: 全选
int *a=malloc(sizeof(int));
int *b=malloc(sizeof(int));
int *tmp;
tmp=b;
a=b;
free(b);
free(tmp);