JohnnyStant
JohnnyStant

Reputation: 1

Does GC.CollectionCount Only analyze the Generational Heap? C# .netcore

The MSDN documentation for GC.CollectionCount states: "Returns the number of times garbage collection has occurred for the specified generation of objects."

Does this mean it only performs this analyzation on the Generational Heap Or Is There Some Way To Measure The Amount Of Collections occurred In The Large Object Heap As well?

Upvotes: 0

Views: 134

Answers (1)

TheGeneral
TheGeneral

Reputation: 81573

You really shouldn't be too worried about these types of methods unless you are building something very specific or have a targeted use case. Usually, you would get this information from a the result of a memory profiler which will give you much more useful information

Some relevant information

Generations

Newly allocated objects form a new generation of objects and are implicitly generation 0 collections. However, if they are large objects, they go on the large object heap (LOH), which is sometimes referred to as generation 3. Generation 3 is a physical generation that's logically collected as part of generation 2.

With GC.CollectionCount it takes a generation integer, so you can specify 3 if you like

In regards to GC.Collect this will do a full collect of all generations.

There is obviously a lot more to this topic which has been glossed over. However, the following is a good place to start

Fundamentals of garbage collection

Upvotes: 1

Related Questions