本文介绍了被垃圾收集器在一个单独的进程中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有垃圾收集器在一个单独的进程启动?

例如:

  1. 如果我们尝试测量所采取的一些片code和在该垃圾收集器开始收集,处理时间将它开始在一个新的处理或在相同的工序

  2. 时,它的工作像下面这样?

      // code(流程1)
     - >垃圾收集器运行(流程1)
    // code(流程1)
     

    还是这个样子?

      // code(流程1)
     - >垃圾收集器运行(过程2)
    // code(流程1)
     

解决方案

在垃圾收集器运行触发垃圾收集,工作在同一个进程中的线程。它停止所有当前线程,并执行本身。它不启动另一个进程肯定,你会看到,在Windows中。

MSDN

(这仅适用于工作站,正如刚才 DrKoch )。服务器有一个后台线程运行垃圾回收。

如果您引用的文档并发垃圾回收的搜索,你会文本GC线程,它支持这一点。

您可以强制在一个单独的线程中运行garabage集合,如果你想。把这个在你的的app.config

<结构>   <运行>      < gcServer启用=真/>   < /运行>< /结构>

(从这个答案

又读The .NET框架4.5包括新的垃圾收集器增强了客户端和服务器应用,所建议的亚当Houldsworth ,有关改变垃圾收集器的工作原理,因为.NET 4.5的方式

Does the garbage collector start in a separate process?

For example:

  1. If we try to measure process time taken by some piece of code and during this the garbage collector starts collecting, will it start on a new process or in the same process?

  2. Is it working like the following?

    //Code (Process 1)
    --> Garbage Collector Run (Process 1)
    //Code (Process 1)
    

    Or like this?

    //Code (Process 1)
    --> Garbage Collector Run (Process 2)
    //Code (Process 1)
    

解决方案

The garbage collector runs the thread that triggered garbage collection, on the very same process. It stops all current thread, and executes itself. It doesn't start another process for sure, you would have seen that in Windows.

From MSDN:

(This applies to workstations only, as pointed out by DrKoch). Servers have a background thread running for garbage collection.

If you search in the referenced documentation for "Concurrent garbage collection", you will the text "GC thread", which supporting this.

You can force to run garabage collection in a separate thread, if you want to. Put this in your app.config:

<configuration>
   <runtime>
      <gcServer enabled="true"/>
   </runtime>
</configuration>

(from this answer)

Also read The .NET Framework 4.5 includes new garbage collector enhancements for client and server apps, as suggested by Adam Houldsworth, about changes in the way the garbage collector works since .NET 4.5.

这篇关于被垃圾收集器在一个单独的进程中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 02:12