Concept of Common Language Runtime Environment (CLR)

Concept of Common Language Runtime Environment (CLR)
Rating: 5 - 1 Votes

Concept of Common Language Runtime Environment (CLR)

C#CLR or Common Language Runtime is the main execution layer of .NET framework.   This layer manages all the low level details of any .NET application like managing threads, doing security checks, garbage collection etc.  If any .NET application gives error during its execution time, CLR will notify you about the error details.

The CLR offers a portability feature, due to which you can easily move your application from 1 platfrom to another platform without any trouble.  The question is, how it is possible?   All the previous applications, which were based on COM model contains Unmanaged Code.  On the other hand, all the applications based on .NET framework contains Managed Code.  Now, you do wants to know what is Managed Code and Unmanaged Code?

Unmanaged code is basically belongs to COM based languages, which on compilation generates a machine specific native code.  Thats the only reason, you can’t run a Windows app on any other platform.  On the other hand, Managed code is compiled into CIL instruction set, which is known as Common Intermediate Language.  Whenever you compile a .NET application, an assembly is created and it contains only CIL instruction set.  Later, when you execute that assembly, CLR converts that Managed Code into machine specific native code using JIT compiler.   Thats the only reason, you can run .NET apps on any other platform without any trouble.

The CLR also offers grabage collection feature.  In the previous COM model based languages, you have to take care of memory management to avoid memory overflow or memory leak issues.  But in .NET, you don’t need to take care of it.  CLR will do the job for you and will remove all the non-required objects from memory when necessary.  We will discuss it in more details in the later chapters.