UMBC CS 201, Fall 05
UMBC CMSC 201 Fall '05
CSEE | 201 | 201 F'05 | lectures | news | help

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.

CSEE | 201 | 201 F'05 | lectures | news | help

Sunday, 21-Aug-2005 09:53:28 EDT