1
Reply

what is the concept of heap in memory management in c#?

asma farrukh

asma farrukh

15y
7.9k
0
Reply

    The stack is the section of memory that is allocated for variables within functions.

    Data is stored in stack using the Last In First Out (LIFO) method. This means that storage in the memory is allocated and de allocated at only one end of the memory called the top of the stack. Stack is a section of memory and its associated registers that is used for temporary storage of information in which the most recently stored item is the first to be retrieved.

    The heap is an area of memory used for dynamic memory allocation. Blocks of memory are allocated and freed in this case in an arbitrary order. The pattern of allocation and size of blocks is not known until run time.

    What we need to know here?
    The reference types will go the heap memory
    The value type will go the heap or stack based on where it is declared.

    Example:

    Class MyClass
    {
    int x;
    Public int mymethod()
    {
       Int y;
    }
    }

    Here, both x & y are value types but  x will go to heap and y will go to stack.