Common Language Runtime in C#

Common Language Runtime that is CLR is a Microsoft product of Common Language Infrastructure , which is an international standard and it is a basis for Creating,Executing and Developing enviornments in which languages and libraries work together. CLR can host a variety of languages and provides interoperability between their code.

CLR, provides functionalities such as Memory Management ,Exception Handling, Debugging, Security, Thread Execution , Code Execution,Code safety , Verification and Compilation.

The CLR automatically releases the resources when they are no longer in use. This Automatic Memory Management resolves the issue of memory leaks and invalid memory references.

CLR provides code access security on the code of an application. Code Access Security is the security system of CLR that prevents unauthorized access to use resources and operations.

Memory Management by CLR

One of the most important service that the CLR provides during Managed Execution is the Automatic Memory Management. The CLR uses Garbage Collector to manage the allocation and release of memory for an application. It reduces the burden of writing codes to manage memory while developing managed applications.

Automatic Memory Management removes many common problems such as forgetting to free an object which results in memory leaks or attempting to access memory for an object that is already free.

Managed and Unmanaged Code

Image is not available

Managed code is the code that is directly executed by CLR. The CLR compiles the applications to the Intermediate code and not the machine code. This IL Code alongwith the Metadata further compiled by Just-In-Time compiler and produced native code.The applications compiled in managed code enviornment automatically have CLR services such as type checking, Security and Automatic Garbage Collection. CLR performs following steps to execute a piece of code.
1.Selecting a Language compiler.
2.Compiling the code to IL.
3.Compiling the IL to native code.
4.Executing the code.

Unmanaged code directly compiles to the machine code and runs on the machine where it has been compiled. It does not have services such as Security or Memory Management by the Run Time.

Side by Side Execution

The process of executing multiple versions of an application or a component on a computer is known as Side by Side execution.The .Net Framework supports Side by Side execution of multiple versions of CLR , Applications, Components,Compilers and runtime. It allows multiple versions of an Assembly or Application to be installed on the same computer at the same time.

Image is not available

Image is not available

About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server, EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.