Hi, I'm new to C++, I can't get my head around why this isn't working...
I'm creating a 2D pointer to an array of unsigned char's like so:
The 2D array is for storing a greyscale image...the image is being loaded into the array correctly and I can manipulate and write it back to file etc. But when I come to delete the array - the memory isn't being freed/deleted...
But after doing this, if I print say ImagePtr[x][y]; the values are still there, surely by trying this the program should crash?
Many thanks if anyone can see what I'm doing wrong...
I'm creating a 2D pointer to an array of unsigned char's like so:
Code:
unsigned char **ImagePtr;
ImagePtr = new unsigned char *[width];
for (int i=0 i<width; i++)
{
ImagePtr[i] = new unsigned char[height];
}
The 2D array is for storing a greyscale image...the image is being loaded into the array correctly and I can manipulate and write it back to file etc. But when I come to delete the array - the memory isn't being freed/deleted...
Code:
for (int i=0; i<width; i++)
{
delete[] ImagePtr[i];
}
delete[] ImagePtr;
But after doing this, if I print say ImagePtr[x][y]; the values are still there, surely by trying this the program should crash?
Many thanks if anyone can see what I'm doing wrong...