.NET Garbage Collector - what is its thread priority?

前端 未结 5 1494
囚心锁ツ
囚心锁ツ 2021-01-01 01:50

I have found some great articles (Maoni, Richter #1, Richter #2) giving many details as to the theory and practice of the GC, yet I cannot find anything that states how the

5条回答
  •  感动是毒
    2021-01-01 02:35

    In CLR via C#, Richter explains that:

    A special high-priority CLR thread is dedicated to calling Finalize methods

    (see the "Finalization Internals" heading of chapter 20)

    This is the only context in which he talks about a garbage collector thread. A little earlier in the chapter, he explains that garbage collection is started in response to one of the following events:

    • Generation 0 is full
    • Call to GC.Collect
    • Windows is reporting low memory conditions
    • The CLR is unloading an AppDomain
    • The CLR is shutting down

    ...which suggests that the only thread created by the garbage collector is this single, "high-priority" finalizer thread.

    Edit: He then goes on, in "Concurrent Collection", to explain that:

    On a multiprocessor system running the workstation version of the execution engine, the garbage collector has an additional background thread to collect objects concurrently while the application runs. [...] The garbage collector has a normal priority background thread that marks unreachable objects.

提交回复
热议问题