In an unmanaged runtime, such as C or C++, you allocate and free up memory for your application through code. A managed runtime, on the other hand, typically has a process governor that manages memory for your application so that you don’t have to. The mechanism that does this is usually referred to as the garbage collector. The .NET runtime has a configurable garbage collector that usually does just fine without software developers caring very much about it. Normally, it just works and does a very good job of managing memory for your app. It can be important, however, to understand how the garbage collector works at times, even if you never need to change the way it operates.
.NET Garbage Collection Basics
The garbage collector is invoked by the runtime to clean up unused memory and defragment the heap generally whenever the application feels pressure to do so. While you can request that garbage collection happen at specific points in your app, you cannot explicitly start garbage collection yourself. And, that being said, it is generally frowned upon to make calls to GC.Collect(). Read more