Lecture 3: Dynamic Memory Allocation and Garbage Collection

Background Material

Reading

Theme

In functional programming there is no notion of memory: computation proceeds be returing values and names are just used as shorthand for the values of expressions since there is no assignment. Thus the computation of a functional program will produce many values which when implemented must be stored somewhere. Since values are needed dynamically as the program is executed memory must be allocated dynamically. If many values are required memory requirements may become an issue. However, values that are no longer being used become garbage and in principle could be used again. The process of collecting memory that is no longer being used is called garbage collection.

In this lecture we present an overview of techniques for dynamic memory allocation and garbage collection.

Topics

  1. cons cells and list allocation (uniform size)
  2. extent and overlap
  3. garbage collection (mark and sweep)
  4. variable size allocation
  5. reference counting

Sample Functions

slides

Exercises

Created: April 10, 2008 (revised April 16, 2009) by jjohnson AT cs DOT drexel DOT edu