free of doubly linked list
问题 I am using a doubly linked list in a C program. I am getting confused about freeing the memory. Should I free the list node by node? Or, by assigning head and tail nodes to NULL? 回答1: You have to traverse the list and free each node. If you only set the head and tail pointers to NULL the list nodes are still in the heap and you have no pointers to them and that's a classic memory leak. Here's some pseudocode: Node* current = head; while( current != NULL ) { Node* next = current->Next; free(