Generally, programming languages use two different techniques for allocation
of memory.
-
Stack-based allocation. Amount of space required is determined at
compile time, based on static types of variables.
Memory allocation and release is tied to procedure entry/exit.
Can be performed very efficiently.
-
Heap-based allocation. Amount of space used can be determined at
run-time, based upon dynamic considerations.
Memory allocation and release is not tied to procedure entry/exit,
and either must be handled by user or by a run-time library (garbage
collection). Generally considered to be somewhat less efficient.