Safe deletion of multidimensional char**

I have a multi dimensional char** array which I'm looking to safely delete without any leaks. I was doing some research and read somewhere that simply calling delete[] would suffice. I have my doubts.

What would be safe?

That depends on how the array was allocated.
Last edited on
1
2
3
4
5
	multiArray = new char*[height];
	for (int i = 0; i < height; i++)
	{
		multiArray[i] = new char[width];
	}
Then like this:

1
2
3
4
5
for(int i = 0; i < height; i++)
{
   delete [] multiArray[i];
}
delete [] multiArray;
Brilliant, makes sense since it's a pointer to a pointer. I guess if it was a normal multi dimensional array with just a pointer then the first delete[] in the loop wouldn't be necessary.
Topic archived. No new replies allowed.