Previous    Next

Activation Records

stack: an orderly pile or heap

Webster's Dictionary


In almost any modern coding language, a function may have local variables that are created upon entry to the function. Several invocations of the function may exist at the same time, and each invocation has its own instantiations of local variables. In the Java method

int f(int x) {
 int y = x+x;
 if (y<10)
 return f(y);
 return y-1;

a new instantiation of x is created (and initialized by f's caller) each time that f is called. Because there are recursive calls, many of these x's exist simultaneously. Similarly, a new instantiation of y is created each time the body of f is entered.

In many languages (including C, Pascal, and Java), local variables are destroyed when a function returns. Since a function returns only after all the functions it has called have returned, we say that function calls behave in last-in-first-out (LIFO) fashion. If local variables are created on function entry and destroyed on function exit, then we can use a LIFO data structure - a stack - to hold them.

JaVaScreenshot Previous    Next