垃圾收集器 运行 是在一个单独的进程中吗?
Is the garbage collector running in a separate process?
垃圾收集器是否在单独的进程中启动?
例如:
如果我们尝试测量某段代码所花费的处理时间,并且在此期间垃圾收集器开始收集,它会在新进程上还是在同一进程中启动?
是不是像下面这样工作?
//Code (Process 1)
--> Garbage Collector Run (Process 1)
//Code (Process 1)
或者像这样?
//Code (Process 1)
--> Garbage Collector Run (Process 2)
//Code (Process 1)
垃圾收集器 运行 是在同一进程上触发垃圾收集的线程。它停止所有当前线程,并自行执行。它肯定不会启动另一个进程,您会在 Windows.
中看到它
来自MSDN:
Before a garbage collection starts, all managed threads are suspended except for the thread that triggered the garbage collection.
(这仅适用于工作站,如 所指出)。服务器有一个后台线程 运行ning 用于垃圾收集。
如果您在参考文档中搜索 "Concurrent garbage collection",您将得到文本 "GC thread",它支持这一点。
如果需要,您可以在单独的线程中强制 运行 垃圾收集。将其放入您的 app.config
:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
(来自 this answer)
另请阅读 The .NET Framework 4.5 includes new garbage collector enhancements for client and server apps, as suggested by Adam Houldsworth,了解自 .NET 4.5 以来垃圾收集器工作方式的变化。
首先有进程和线程的区别。
正如@CodesInChaos 指出的那样,每个 进程 都有自己的地址 space,因此 运行 单独进程中的 GC 没有任何意义。
如果我们谈论 线程:
"Workstation" 和 "Server" 是有区别的。在工作站上,它在用户线程之一上运行:
The collection occurs on the user thread that triggered the garbage collection
在服务器上,它在单独的专用线程中运行:
The collection occurs on multiple dedicated threads that are running at THREAD_PRIORITY_HIGHEST priority level.
如果你的机器被认为是"server"取决于配置:
<gcServer> element of the runtime configuration schema
垃圾收集器是否在单独的进程中启动?
例如:
如果我们尝试测量某段代码所花费的处理时间,并且在此期间垃圾收集器开始收集,它会在新进程上还是在同一进程中启动?
是不是像下面这样工作?
//Code (Process 1) --> Garbage Collector Run (Process 1) //Code (Process 1)
或者像这样?
//Code (Process 1) --> Garbage Collector Run (Process 2) //Code (Process 1)
垃圾收集器 运行 是在同一进程上触发垃圾收集的线程。它停止所有当前线程,并自行执行。它肯定不会启动另一个进程,您会在 Windows.
中看到它来自MSDN:
Before a garbage collection starts, all managed threads are suspended except for the thread that triggered the garbage collection.
(这仅适用于工作站,如
如果您在参考文档中搜索 "Concurrent garbage collection",您将得到文本 "GC thread",它支持这一点。
如果需要,您可以在单独的线程中强制 运行 垃圾收集。将其放入您的 app.config
:
<configuration>
<runtime>
<gcServer enabled="true"/>
</runtime>
</configuration>
(来自 this answer)
另请阅读 The .NET Framework 4.5 includes new garbage collector enhancements for client and server apps, as suggested by Adam Houldsworth,了解自 .NET 4.5 以来垃圾收集器工作方式的变化。
首先有进程和线程的区别。 正如@CodesInChaos 指出的那样,每个 进程 都有自己的地址 space,因此 运行 单独进程中的 GC 没有任何意义。
如果我们谈论 线程: "Workstation" 和 "Server" 是有区别的。在工作站上,它在用户线程之一上运行:
The collection occurs on the user thread that triggered the garbage collection
在服务器上,它在单独的专用线程中运行:
The collection occurs on multiple dedicated threads that are running at THREAD_PRIORITY_HIGHEST priority level.
如果你的机器被认为是"server"取决于配置:
<gcServer> element of the runtime configuration schema