C# Memory Tricks: Learn How To Master The Garbage Collector
Introduction to .NET memory management
Heap: Whenever an object/variable is created using the new keyword, it's stored in the Heap section of memory.
How to release the Heap memory?
In some languages such as C++, we have the "delete" keyword to free dynamically allocated memory on the heap.
But in the.NET Framework, we don't have such. Here we have the Garbage collector which continuously deletes objects that is no longer used for our code.
But why has Microsoft did not implement the "delete" keyword?
Disadvantages of Garbage collection
Fundamentals of the .NET Framework
The Stack: Block of memory that is used for calling methods and storing local variables.
The Heap:
Value type:
If we have local variables of value type they will store in Stack along with value and type, like this:-
int a = 1234;
int b = 0;
-----------------
int b = a;
Reference type:
Type of variable that refers to the value stored on the heap.
Boxing and Unboxing:
A detailed look at Garbage Collection
Simple tricks to improve memory allocation