What is the Stack?
Stack is a LIFO (Last In First Out) structure and hold Value Types such as bool, byte, char, decimal, double, enum, float, int, long, sbyte, short, struct, uint, ulong, ushort. Variables are stored directly to the memory and can be accessed fast. The variables stored in the stack can’t be resized and their allocation is static. Stack also contains pointers (or reference) that are pointing to reference types.
What is the Heap?
Heap on the other hand is an area of memory where chunks are allocated to store certain kinds of data objects. Data in the Heap can be added or stored in any order and are stored indirectly. Reference Types such as class, interface, delegate, object, string, all live in the Heap. The memory allocation is dynamic and variables can be resized. Access on the heap is slow. Memory allocation and release is managed by a Garbage Collector.
If you would like to read more stories, check out my blog.