In Traditional Memory Management
(as opposed to Garbage-Collection
) memory is divided into three main areas: global data, the stack, and the heap. The Global Data
area is a collection global variables, it is of constant size and globally visible throughout the program's execution. The Stack
contains a series of Stack Frame
s, each representing a function scope. Both of these areas contain references, called Roots
, into the Heap
which holds Object
s are memory regions used for application dependent purposes and may contain arbitrary data including pointers.
Objects on the heap are generally allocated and de-allocated explicitly, an application must be able to detect when a Object is no longer needed so that it may be de-allocated and the memory reused. The structure that manages de-allocated memory waiting for re-allocation is called a Free List, though often implemented as an array of lists or a tree of some variety. Stack Frames are de-allocated when the procedure associated with them terminates.
This form of memory management has several long standing problems, which, fall into three main categories:
Incorrect program decisions as to whether a Object is still in use lead either to memory leaks (if unneeded Objects are kept) or to dangling pointers (if needed Objects are de-allocated). Both of these lead to catastrophic results in non-trivial programs.
The structure and types of Objects on the heap are highly dependent on the domain of the application and the language in which it is implemented. In general the types of Objects are not determinable by examination of the Objects themselves.
Allocation and de-allocation using traditional algorithms such as first-fit, binary search tree or partitioning by size can (in some circumstances) be very expensive in terms of processor time and memory accesses.
Additionally, since it forces routines which operate on a Objects to be aware of other routines operating on the same chunk in order to make de-allocation decisions, traditional memory management impedes truly modular programming.
A good review paper on memory management is: Paul R. Wilson. Uniprocessor garbage collection techniques. In Proc of International Workshop on Memory Management in the Springer-Verlag Lecture Notes in Computer Science series., St. Malo, France, September 1992.