Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why configuring .NET Garbage Collector doesn't work?

I'm struggling to understand how can I change the garbage collector mode on .NET 4.0 from Workstation to Concurrent mode. I've found out I need to add these lines to some config file:

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

However, I'm not sure what configuration file they mean here. Nevertheless, I went to the machine.config under C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config hoping that this was a machine-wide setting and still that didn't help. I noticed my dlls also had their own config files, but updating those also didn't help. Note that my application doesn't have an app.config.

Later on I've run a test dll in nunit, where I also wanted to set the GC mode to Concurrent. So I thought I should configure nunit: nunit-x86.exe.config under C:\Program Files (x86)\NUnit 2.6.2\bin. This also didn't have any effect.

Any clues ? Which config file should I update ?

Thanks, Greetings, Sorin

like image 549
Sorin-Alexandru Cristescu Avatar asked Jan 27 '26 07:01

Sorin-Alexandru Cristescu


1 Answers

There are several possible reasons for this. Off the top of my head:

  • Not having an app.config file is clearly a problem. The CLR only reads the yourapp.exe.config file for configuration
  • You might not have workstation GC enabled at all. The default for the server version of Windows is the server GC, configured with the <gcServer> element in the .config file
  • You might be running with the debugger and have the Visual Studio Hosting Process enabled. Which uses a different .config file since the EXE name is different. The config file must be named yourapp.vshost.exe.config

Not much point at guessing at this when you can see which .config file is being used. Run Fuslogvw.exe from the elevated Visual Studio Command Prompt (right-click the shortcut and choose Run as Administrator). Click Settings and tick "Log all binds to disk". Run your program. Click Refresh and look at one of the log entries, you'll see a line that resembles:

LOG: Using application configuration file: c:\projects2\ConsoleApplication43\bin\Debug\ConsoleApplication43.vshost.exe.Config

Just an example, this one was generated for a dummy console mode app, started with F5 and with the Hosting Process option ticked in the project's Debug tab.

like image 107
Hans Passant Avatar answered Feb 01 '26 16:02

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!