Creation of New Variables

Space for variables can be created in one of two different ways. Stack-based memory is memory that is allocated automatically when a procedure is started. Space exists as long as the procedure executes, and is automatically recovered when the procedure exits. The user does not invoke any explicit statement to create stack based memory.

On the other hand, dynamic memory, also called heap-based memory, is allocated only in response to an explicit request, in many languages indicated by an operator named new. Such memory is not tied to procedure entry and exit.

How heap based memory is recovered is different in different languages, a topic we will take up next.

[audio] [real] Text to accompany slide3, in Chapter 4 of An Introduction to Object-Oriented Programming