Skip to content

Managed Class vs Unmanaged Class in C# #134

Answered by christiannagel
ShervanN asked this question in Q&A
Discussion options

You must be logged in to vote

A better name would be a managed type and an unmanaged type. A managed type is managed by the garbage collector - the garbage collector frees memory, but also can change the address of an object (it moves objects during garbage collect runs and thus can compact memory). An unmanaged type is not managed by the garbage collector.

One example is a struct type which is stored on the stack. Be aware that a struct type can also be stored on the heap which happens with boxing. A ref struct type can never be stored on the heap, this type only works when it's on the stack.

Another example for an unmanaged type is important with platform interop. Instead of allocating memory on the managed heap (the

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by christiannagel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants