Memory Leaks

What is a memory leak ?

If you don't free all of the memory you've allocated, then you have a memory leak.

The statement

free(head); of course does not free all the memory that was allocated for your linked list. That's why you were told to write a DestroyList() function to be added to the linked list code. DestroyList() should traverse the list and free all of the nodes as it goes.

Although many programmers feel it is a waste of time to clean up after themselves by freeing memory that was dynamically allocated, failing to do so can cause systems to crash. Programs that run continuously and need to dynamically allocate more memory (and also should be freeing some) as they run, can quickly accumulate lots of wasted space.