Chapter03 Names Scopes and Bindings 4e
Chapter03 Names Scopes and Bindings 4e
• Key events
– creation of objects
– creation of bindings
– references to variables (which use bindings)
– (temporary) deactivation of bindings
– reactivation of bindings
– destruction of bindings
– destruction of objects
Lifetime and Storage Management
• The period of time from creation to destruction is
called the LIFETIME of a binding
– If object outlives binding it's garbage
– If binding outlives object it's a dangling
reference
• The textual region of the program in which the
binding is active is its scope
• In addition to talking about the scope of a binding,
we sometimes use the word scope as a noun all by
itself, without an indirect object
Lifetime and Storage Management
• Storage Allocation mechanisms
–Static
–Stack
–Heap
• Static allocation for
–code
–globals
–static or own variables
–explicit constants (including strings, sets, etc)
–scalars may be stored in the instructions
• On subroutine exit:
– destroy bindings for local variables
– reactivate bindings for global variables that were
deactivated
• Algol 68:
– ELABORATION = process of creating bindings when
entering a scope
• Ada (re-popularized the term elaboration):
– storage may be allocated, tasks started, even exceptions
propagated as a result of the elaboration of declarations
Scope Rules