Implement function to free the memory used by the list.