Alex Aparin
Alex Aparin

Reputation: 4512

Memory management of native heap in CLR

I want to understand memory management of native heap in CLR. I know that CLR has managed heap. For example, I am using C++/CLI binding library, which evolves some C++ library. During its work, C++ library can allocate objects. Will these objects be allocated at native heap of CLR? As I understood, CLR has native and managed heaps which will be created during running of CLR.

Upvotes: 1

Views: 1245

Answers (1)

Hans Passant
Hans Passant

Reputation: 941635

The CLR does not have a "native heap". When you use malloc() or new in your code then you use the C runtime allocator. The exact same one you'd use in a native C or C++ program. Which for VS versions 2010 or less allocates from its own heap (created with HeapCreate), for 2012 and up allocates from the default process heap (GetProcessHeap).

There is no "management" at all, you are responsible for calling free() or delete, just like you are in a native C or C++ program. Failure to do so cause a memory leak, the garbage collector does not help you at all.

Upvotes: 4

Related Questions