Compartilhar via


How to enable CLR Server GC?

This is one of the mostly asked questions about CLR GC.

CLR's GC has two modes: Server GC and WorkStation GC. The difference is discussed briefly in Gregor Noriski's MSDN article about writing high performance managed application(https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/highperfmanagedapps.asp).

In .Net framework 1.0 and 1.1, the only supported way to enable server GC is going through CLR's hosting API. Steven Pratschner provided a sample in a newsgroup post: https://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=8d37b7b7c04b7609&seekm=O6jAptPPDHA.2284%40cpmsftngxa06.phx.gbl#link2

In Whidbey (.Net framework 2.0) and 1.1 Service Pack 1, CLR introduces a config file option to enable server GC. The syntax is following:

<Configuration>
    <runtime>
        <gcServer enabled=“true“ />
    </runtime>
</Configuration>

This can be put in app.config or machine.config. App.config is preferred so that it won't affect all the applications on the machine.

In .Net framework 1.1 you can check if Server GC is enabled by checking whether mscorwks.dll or mscorsvr.dll is loaded. If mscorsvr.dll is loaded, then Server GC is enabled.

In Whidbey mscorsvr.dll is merged into mscorwks.dll, so the above technique will not work. Instead, System.Environment.IsServerGC should be used to check against Server GC.

This config file should work with Whidbey Beta1 and .Net framework 1.1 SP1 Technical Preview. Both are available now.

Comments

  • Anonymous
    July 13, 2004
    As one writer explains, one of the most common asked questions about CLR GC is: "How to enable CLR Server GC?" Well, here you will find out about a config file that allows you to accomplish this task. Short, but...

  • Anonymous
    July 14, 2004
    Server GC ? WorkStation GC ???(.Net framework 1.1 SP1)

  • Anonymous
    July 14, 2004
    Wouldn't the IsServerGC be better placed on System.GC class, as it applies to the Garbage Collector?

  • Anonymous
    July 14, 2004
    David,

    This is a good question. The original thinking is that this describes the state of the system. We will evaluate your suggestion. Since Whidbey is still in beta1, we still have time to make a change.

  • Anonymous
    June 10, 2008
    In the previous posts in this series, we have looked at a multitude of features provided by the PFX June

  • Anonymous
    June 10, 2009
    PingBack from http://soci.hu/blog/index.php/2009/06/11/a-tobbszalu-skalazas-nehezsegei/