Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

CLR (Common Language Runtime)

Lesson 7 of 27 in the free C# Programming notes on Siksha Sarovar, written by Rohit Jangra.

The Engine Under the Hood

The Common Language Runtime (CLR) is the virtual machine component of the .NET framework. It is responsible for managing the execution of .NET programs.

Study Deep: How Garbage Collection Actually Works

The CLR's Garbage Collector (GC) doesn't just "free memory." It uses a Generational Strategy:

  1. Generation 0: New objects go here. Cleaned very frequently.
  2. Generation 1: If an object survives a Gen 0 cleanup, it's promoted here. Acts as a "buffer."
  3. Generation 2: Long-lived objects (like static data). Cleaned rarely.
  • The Logic: The GC assumes that "new objects die young" and "old objects live long." This makes memory cleanup incredibly fast because it doesn't scan the whole memory every time.

Key Responsibilities of CLR

The CLR performs a multitude of services that you, as a programmer, typically don't have to worry about:

  1. Memory Management (Garbage Collection): The CLR automatically detects when memory is no longer being used and releases it. This prevents memory leaks, a common plague in C++ development.
  2. Thread Management: It manages the underlying operating system threads for parallel execution.
  3. Exception Handling: It provides a unified way to handle runtime errors across different languages.
  4. Security Management: It verifies that the code is allowed to perform specific actions (like reading a file or accessing the network).
  5. Type Safety: It ensures that an object is accessed in compatible ways (e.g., ensuring an array index is within bounds).

The Execution Process

  1. Source Code is compiled to MSIL.
  2. CLR loads the MSIL.
  3. JIT Compiler (inside CLR) converts MSIL to Native Code.
  4. OS executes the Native Code.