Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managed and Unmanaged heap

What is an unmanaged heap?

I thought any object based memory that the CLR manages was the managed heap, so why do we talk about an unmanaged heap?

like image 817
WPF-it Avatar asked Jul 08 '11 08:07

WPF-it


2 Answers

Imagine you call a Win32 function using P/Invoke, and that allocates some memory using malloc. The garbage collector has no visibility of that memory - it's unmanaged.

That may or may not be the context in which you've heard the term, of course - if you could point us to some examples, we may be able to help you more.

like image 51
Jon Skeet Avatar answered Sep 28 '22 00:09

Jon Skeet


As per John Skeet - the managed heap is the one that .net will manage for you, that all standard objects are created on, that you normally don't need to bother too much about because it is managed.

unmanaged means that you are personally allocating memory, and so you are personally responsible for deallocating it, managing it yourself, and keeping track of what is being used.

So yes, object memory ( in the sense of normal object creation and destruction, things that derive from object ) is managed. It is the other stuff you need to worry about - non objects and memory allocated for them.

like image 24
Schroedingers Cat Avatar answered Sep 28 '22 02:09

Schroedingers Cat