Recall & Review
beginner
What is the stack in memory management?
The stack is a special area of memory that stores local variables and function call information. It works like a stack of plates: last in, first out. When a function is called, its variables are pushed onto the stack, and when it returns, they are popped off.
Click to reveal answer
beginner
What is the heap in memory management?
The heap is a large pool of memory used for dynamic allocation. Objects created with 'new' are stored here. Unlike the stack, the heap does not follow last-in, first-out order and requires manual or automatic management to free memory.
Click to reveal answer
intermediate
How does the stack differ from the heap in terms of size and speed?
The stack is smaller but faster because it uses a simple last-in, first-out structure. The heap is larger but slower because it manages memory dynamically and can become fragmented.
Click to reveal answer
intermediate
Why are value types stored on the stack and reference types on the heap in C#?
Value types (like int, struct) are stored on the stack because they have a fixed size and short lifetime. Reference types (like objects) are stored on the heap because they can be larger and have a lifetime that extends beyond the current function call.
Click to reveal answer
beginner
What happens if the stack runs out of space?
If the stack runs out of space, a stack overflow occurs, causing the program to crash or throw an error. This usually happens with very deep or infinite recursion.
Click to reveal answer
Where are local variables typically stored in C#?
✗ Incorrect
Local variables are stored on the stack because they have a short lifetime and fixed size.
Which memory area stores objects created with 'new' in C#?
✗ Incorrect
Objects created with 'new' are stored on the heap because they require dynamic memory allocation.
What is a key characteristic of the stack memory?
✗ Incorrect
The stack uses last-in, first-out order to manage function calls and local variables.
What can cause a stack overflow error?
✗ Incorrect
Stack overflow happens when the stack runs out of space, often due to deep or infinite recursion.
Why is heap memory slower than stack memory?
✗ Incorrect
Heap memory is slower because it needs to manage dynamic allocation and can become fragmented.
Explain the difference between stack and heap memory using a real-life analogy.
Think about how you organize things you use often versus things you store for later.
You got /4 concepts.
Describe what happens in memory when a C# method creates a local variable and an object with 'new'.
Consider where each type of data lives during the method execution.
You got /4 concepts.