当我在 C++ 中多次初始化一个变量时,内存位置会发生什么变化?例如:
LPWSTR sampleString = new whcar_t[10];
//some operations here
sampleString = new wchar_t[2];
//some operations here
sampleString = new wchar_t[25];
//some operations here
如果我使用 delete [] sampleString;
删除内存,是否会清除所有关联的内存位置?
最佳答案
没有,只有最后一个。其余的一切都将永远消失。这就是所谓的“内存泄漏”。
关于c++ - 在 C++ 中多次初始化数组时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11465552/