I am trying to free memory allocated through malloc()using free().
Some of the structures that he does for free, but leave some of the ways that they are, and they also remain associated with their children. It also never frees a root (gRootPtr)for a binary tree.
I use Xcode to find out if the memory used by the binary tree has been freed, and also use the if statement.
The code I use to free memory is:
void FreeMemory(InfoDefiner *InfoCarrier)
{
if ((*InfoCarrier) != NULL) {
FreeMemory((&(*InfoCarrier)->left));
FreeMemory((&(*InfoCarrier)->right));
free((*InfoCarrier));
}
}
The code I use to find out if memory is freed.
if (gRootPtr != NULL) {
return 1;
}
else{
return 0;
}
source
share