C# has at its core a rigorous memory management scheme built into the .NET Framework. This means that programmers have to write less code. Automatic memory-management policies are carried out by the garbage collector, and these policies mean that the programmer doesn’t have to manually allocate and free memory used by objects.
Here is the general lifecycle of an object:
1. The object is created.
2. Memory is allocated for the object.
3. The constructor is run.
4. The object is now live.
5. If the object is no longer in use (other than running finalizers), it needs finalization.
6. Finalizers are run (unless overridden).
7. The object is now inaccessible and is available for the garbage collector to carry out clean-up.
8. The garbage collector frees up associated memory.