i

ASP.Net A Complete Guide

C# Memory Concepts

 Memory Concepts:

To know how Memory allocation works in .net, we need to understand the variables and their values.

The memory slot for a variable is stored on either the stack or the heap. It depends on the variable is declared. We can define any variable as the value type of reference type:

A Value Type: Stores the data within its own memory allocation.

Int count=0;

Here the value 0 is stored in the stack.

Reference Type: Hold a pointer to another memory location that holds the real data.

int[] iArray = new int[5];

In the above example, the space required for the five integers that make up the array is allocated on the heap.

Stack and Heap:

The stack is used for storing the value type and Heap is used for storing the reference type, both stored in the computer's RAM.