Call Stack

Why Trust Techopedia

What Does Call Stack Mean?

A call stack, in C#, is the list of names of methods called at run time from the beginning of a program until the execution of the current statement.

Advertisements

A call stack is mainly intended to keep track of the point to which each active subroutine should return control when it finishes executing. Call stack acts as a tool to debug an application when the method to be traced can be called in more than one context. This forms a better alternative than adding tracing code to all methods that call the given method. Whenever an exception is thrown anywhere in the user code, the Common Language Runtime (CLR) will unwind the call stack and search for the catch block to determine the specific exception type. If there is no appropriate handler, CLR will terminate the application. Call stack, therefore, is used to tell the execution pointer where to go next.

Techopedia Explains Call Stack

Call stack is organized as “stack,” a data structure in memory for storing items in a last-in-first-out manner, so that the caller of the subroutine pushes the return address onto the stack and the called subroutine, after finishing, pops the return address off the call stack to transfer control to that address.

In C#, any application begins with a “main” method, which in turn calls other methods. On every call to a method, the method is added to the top of the stack and is removed from the stack on its return to the caller. Also, the scope of a variable declared in a block is determined from the time its value is pushed onto the stack (as part of call stack) until the execution leaves the block when the variable and the call stack are popped off the stack. Thus, the stack maintains both local variables (value types) and the call stack (stack frames), the size of which indicates the complexity of a program.

Advertisements

Related Terms

Margaret Rouse
Technology expert
Margaret Rouse
Technology expert

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.