When a method call is added to stack, it’s variable(s) memory gets allocated to the stack as well
When the method call is over, the variable(s) memory gets de-allocated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Heap
A
Region of memory used for dynamic memory allocation
Objects created on heap persist beyond the scope of methods or functions that created them
They can be accessed by multiple parts of your program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Heap - reference types
A
Reference types (such as objects, arrays, etc.) are typically allocated on the heap
The memory for these objects are managed by the .NET runtime’s garbage collector -> which determines when objects are no longer needed -> then reclaims their memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
Summary
A
Call stack is mechanism for managing execution flow and local variables during method calls
Heap is region of memory used for dynamic memory allocation where objects with longer lifetimes are stored
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
How arrays are accessed in memory
A
Reference type arrays (such as objects, strings, or instances of classes) are allocated on the heap
Value type arrays (such as integers, doubles, or structs):
Allocated on stack if the variable is local Allocated on heap if the variable is created within a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
How arrays are stored in memory
A
Adjacent blocks of memory stored sequentially
Depending on the data type, allocates a block of memory of that data types size
Base address of array is where the first element is stored