-6

How would I deallocate the 2D array of pointers allocated with this code:

board = new Node ** [r];

//creates a column for each element in the row
for(int i = 0; i < r; i++) {
    board [i] = new Node * [c];
}

It's a 2D array of pointers and for what I have so far in the destructor, it points to the board = line....

Board is a Node ***, like it should be.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
J K
  • 1
  • 7

1 Answers1

3

You should deallocate it in the reverse order that you allocated it in:

for(int i = 0; i < r; i++) {
    delete [] board[i];
}

delete [] board;
wolfPack88
  • 4,163
  • 4
  • 32
  • 47
  • Valgrind still complaining.... that's why I'm confused... but yet everyone else on here has to be rude... O_O – J K Dec 12 '14 at 20:01
  • @LucasMarzocco: If valgrind is still complaining, then it is something other than the deallocation that is causing the issue. Try making a small test case with only the above allocation and deallocation; valgrind will not complain at all. Then slowly add in other aspects of your code and check under valgrind. As soon as you see valgrind start to complain, then you know what line is causing the issue. – wolfPack88 Dec 12 '14 at 20:04