0

I've been reading about c# memory allocation recently, and there are some important concepts: GC heap and managed heap; Some articles describe them as the same thing, that garbage collection is done on the managed heap, while others say that the managed heap contains the load heap and other areas.

garbage-collection The Microsoft article on GC above directly describes the GC operands as managed heaps.I think in a broad sense the GC heap is the managed heap; So from a narrow perspective, what should a managed heap contain, and what exactly is the relationship between a managed heap and a GC heap

morning
  • 1
  • 1
  • Not really a Stackoverflow question, but yes, the Managed heap might be called the GC heap by some. If you start reading more detailed explanations, you'll see references the the areas of the heap allocated for each _Generation_ (Gen0, Gen1, and Gen2) as well as for the _Large Object Heap_. The are all part of the _Managed Heap_ – Flydog57 Aug 16 '23 at 03:30

1 Answers1

0

in summary

GC heap ⊂ Managed heap .

Managed heap = GC heap + Large object heap + High frequency heap + Pinned object heap + etc.

The managed heap is managed and GC'ed as a whole, but the GC heap is the part containing the normal application objects that get compacted and reclaimed by the GC. The other heaps have special behavior. So in general "managed heap" and "GC heap" refer to similar things, but "GC heap" is more precisely just the part of the managed heap that the GC collects and compacts. The managed heap contains other regions too.

Fundamentals of garbage collection

Understanding the Garbage Collector

sep7696
  • 494
  • 2
  • 16
  • Ok, you are right, so far I also know that managed Heap also includes Loader Heap, JIT Code Heap and so on. I've already seen that references to reference types live on the thread stack, while instances live on the GC heap. But static objects are not garbage collected. What I want to know is, where are the static reference type members stored, are they in the high-frequency heap or the load heap? What about the same static value type members? – morning Aug 16 '23 at 06:02
  • @morning the location where static objects are stored depends on whether they are. reference types or value types and static reference type members are stored in the high hrequency heap . static reference types go into the managed heaps high hrequency region, while static value types go into static storage. – sep7696 Aug 16 '23 at 06:14
  • Allocating memory for static members is a whole other story. I found stackoverflow has the answer to this question and I am getting to understand it.[where-are-all-the-static-members-stored](https://stackoverflow.com/questions/38612009/where-are-all-the-static-members-stored) – morning Aug 16 '23 at 06:25
  • 1
    Can you please share concreate quote defining "GC heap"? Because GC manages LOH for example - _"The .NET garbage collector (GC) divides objects up into small and large objects. ... Because of this, the garbage collector places large objects on the large object heap (LOH)."_ ([doc](https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap)). – Guru Stron Aug 16 '23 at 07:45
  • @GuruStron it's clear my previous answer was incorrect. Let me clarify according to Microsoft Document "The garbage collector allocates and moves objects between the managed heap and a reserved region called the garbage collector heap. The garbage collector heap is a compacted region of memory that contains recently allocated objects." So the GC heap is not limited to just a specific region like the ephemeral generation. Rather, it refers to the portion of the managed heap that contains objects actively being allocated and collected Thank you for noticing me – sep7696 Aug 16 '23 at 08:00