[   ^ to index...   |   <-- previous   ]

Fixing LinkedList, ct'd

LinkedList::cleanup() { } LinkedList::copy(LinkedList & other) { }

Remarks on dynamic memory

Many people think that C++'s mechanisms for managing dynamic memory combine danger and complexity in the worst possible way. It is all too easy when managing dynamic memory in a complex class to forget some edge case and end up with a dangling pointer or memory leak. In particular, you have to spend a lot of time worrying about who "owns" a particular piece of allocated memory.

Languages such as Scheme (and other Lisp dialects), Java, ML, Modula-3, Cecil (our homegrown UW language), and many others feature garbage collection, alleviating all these headaches.

Garbage collection guarantees that dangling pointers and memory leaks are impossible by keeping track of which pointers in the stack reference memory in the heap. Periodically, the garbage collector (the runtime system that provides the collection service) scans the stack and the heap and automatically reclaims any unreachable allocated memory.


Last modified: Mon Jul 17 23:33:46 PDT 2000