CLR Garbage Collection - suniladhya/Advantage GitHub Wiki

GC is a part of CLR Manages allocation and deallocation of memory for the application.

When an object is created, it is stored in (adjacent region of address space) the managed heap.

Accessing All the reference type data from managed heap, is faster.

As long as address space is available in the managed heap, the runtime continues to allocate space for new objects.

For Deallocation, the GC periodically executes and performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

For unmanaged code, dispose method is used.

Finalise and Dispose Managed resources are crated and handled by the CLR.

Unmanaged code are not controlled by CLR. eg.DB connection, file handling

https://youtu.be/6_Upud25iFQ

  1. Calling dispose method
  2. Creating a using block

Finalise is created using the class destructor.

Finalise is called by GC.