Managed and Unmanaged Code

Jaydeep Patil
2 min readApr 24, 2022

--

What is Managed and Unmanaged Code?

Managed Code-

- Managed Code means the code which is designed and developed under the .NET Framework called Managed Code.

- The code is designed under .NET and supported many programming languages such as C#, VB.NET, and F#.

- The code is monitored and follows the protocols of Common Langauge Runtime(CLR).

- All the things like Object Creation, Memory Allocation, and Dispose of the object after Its use are the things that are managed under the CLR.

- Also any code which is written in .NET Framework is the Managed Code.

Advantages of Managed Code -

- The CLR will take care of Managed Code like Memory Allocation, Security, and Memory Disposal.

- CLR will automatically check all the things If there are unwanted objects present in the memory then it will check that using a garbage collector and handle the scenario.

Disadvantages of Managed Code -

- The major disadvantage of the Managed Code is we are not able to use memory as per our need and not able to interfere into the CPU Memory Architecture.

Unmanaged Code-

- The Code which is written using the .NET Framework is called Unmanaged Code.

- The Code which is not executed under the CLR like C and C++ is also known as Unmanaged Code.

- All the things like Memory Allocation, Object Creation, and Disposal of that Object is need to taken care of by the developer, there is chances of uncertainty like memory leakage and unwanted memory allocation.

- But .NET Framework provides some techniques using that Unmanaged Code is used as a Manage Code and Vice-Versa by using the Wrapper Classes which are present under the .NET Framework.

Advantages of Unmanaged Code-

- You can run the Unmanaged Code under any environment and platform.

- The code is a little bit faster than managed code.

- Developer will be able to pass some parameters without following the protocols under the Common Language Runtime.

Disadvantages of Unmanaged Code-

- Less Secure than Managed Code.

- It may face memory leakage issues and performance issues.

- It will not support default exception handling, the developer needs to take care of that things.

- Hard to Managed Type Casting.

- It will not support Automatic Memory Management-related things which are provided by CLR under the .NET Framework.

So, This is all about Managed and Unmanaged Code.

I hope you understand the few things related to Managed and Unmanaged Code.

--

--

Jaydeep Patil

Full Stack Developer | .Net Core API | Angular | SQL Server | Docker | Azure | Python