【发布时间】:2009-10-16 18:34:14
【问题描述】:
这段代码是否会导致内存泄漏:
int main(){
int * a = new int[10];
int * b = new int[10];
for(int i = 0 ; i < 10; i++)
{
a[i] = 1;
b[i] = 1;
}
for(int i = 0 ; i < 10; i++)
{
a[i] = b[i]; //each a[i] is allocated 4 bytes on heap
//when we copy b[i] into a[i] do we loose
//the reference to a[i] (hence a leak),
//and replace that reference
//with a reference to a new value?
}
delete[] a;
delete[] b;
}
【问题讨论】:
标签: c++ memory memory-leaks