I was wondering if one of you could confirm that I'm deleting some dynamically allocated memory properly.
The TileWrapper below is initialized as a 2D array of pointers:
private:
TileWrapper*** mLayout;
I've simplified its initialization to show you the important parts:
void generateLayout() {
mLayout = new TileWrapper**[mRows];
for(int i = 0; i < mRows; i++) {
mLayout[i] = new TileWrapper*[mColumns];
}
for(int i = 0; i < mRows; i++) {
for(int j = 0; j < mColumns; j++) {
mLayout[i][j] = new TileWrapper();
}
}
}
The part that I need confirmed is the destruction, shown below:
~Destructor() {
for (int i = 0; i < mRows; i++) {
for (int j = 0; j < mColumns; j++) {
delete mLayout[i][j];
}
delete[] mLayout[i]; // CONFIRM THIS
}
delete[] mLayout; // CONFIRM THIS
}
I'm especially concerned about the deletes that have // CONFIRM THIS afterwards due to the [] characters. Is my code memory-leak proof? Thanks.