下面的代码是否包含内存泄漏。我怀疑确实如此,但我用来检测它们的工具(Visual Studio + Parasoft c++ 测试)没有标记任何东西。如果是我将如何解决它?
//A dynamically allocated array of char pointers
int numOfStrings = 10, numOfChars = 32;
char** data = new char*[numOfStrings];
//Generate each each individual string
for(int i = 0; i <numOfStrings; i++)
data[i] = new char[numOfChars];
//moves the elements 1-5 in the array to the right by one
int index = 1, boundary = 5, sizeToMove = (boundary - index) * sizeof(numOfChars);
memmove(&data[index + 1],&data[index],sizeToMove);
delete[] data;
编辑:
我应该提一下,我已经尝试迭代每个单独的字符串,如下所示,但发生了异常。
for(int i = 0; i< numOfStrings; i++)
delete [] data [i];