Hi All, The "memory leak" fix that was presented in class is only half of the solution. For everyones future reference (mine too), writing functions that return structures (classes) should be avoided. The problem is in code like this: Adjacent a; a = GetAdjacent(args...); or this which is equivalent: Adjacent * a; *a = GetAdjacent(args...); This interferes with freeing memory because the structure Adjacent has pointers to allocated memory. The outline of the fix is to change the passing BACK of a structure to passing a pointer TO the structure as a function argument. The code becomes: Adjacent a; GetAdjacent2(&a, args...); The GetAdjacent2 function is the same, but doesn't use a local copy of an Adjacent structure, but references the "a" created by the calling procedure. This is where all of the memory leaks seem to stem from, and needs to be added to the other suggestions I made during class. You should still "kill" the data structure when you have finished with it. Regards, Stuart The previous suggestions were to: Into Adjacent.cpp: void Adjacent :: kill(void) { free(xs); free(ys); free(dir); } And then mainly in HexBoard.cpp: Adjacent * a = new Adjacent(); change all occurences to Adjacent a; changing of course also all -> to simply . The new code is: The GetAdjacent2 function is presented below. Add it to HexBoard.cpp (don't forget to add a reference to it in HexBoard.h). // This function returns tiles adjacent to another tile // which is a constant and may be either ALL_ADJACENT to get // all tiles or FWD_ADJACENT which is only the first three directions void HexBoard::GetAdjacent2(Adjacent * a, int x, int y, int which) { int d, max; int xa, ya; a->numAdjacent=0; // Select which adjacent tiles we are interested in if (which==FWD_ADJACENT) { max = 3; } else { max = 6; } // Enumerate through the adjacent tiles we are interested in // selecting only those within the confines of the board for (d=0; dadd(d, xa, ya); } } Fixing Memory Leaks in Tantrix Code