tsds
tsds

Reputation: 9020

How to disable explicit garbage collection in .Net 4?

I'm using 3-rd party libraries in my application, where GC.Collect() method is often explicitly called.
The problem is that it produces deadlocks (which is a well known issue of calling gc explicitly).

How can configure my application (app.config) so that it would ignore GC.Collect()?

P.S.: I know how to do this in Java (by using -XX:+DisableExplicitGC flag),
but I have no idea how to do it in .Net.

Upvotes: 2

Views: 1768

Answers (2)

Korijn
Korijn

Reputation: 1403

I'm not aware of any way to "ignore" calls to GC.Collect(). There are a few configuration options available but I doubt they'll solve your deadlocks issue:

<configuration>
    <runtime>
        <gcServer enabled="true|false"/>
        <gcConcurrent enabled="true|false"/>
    </runtime>
</configuration>

They basically switch garbage collection modes but they don't disable the calls to GC.Collect().

MSDN: gcServer, gcConcurrent.

I think it would be wiser to investigate why this is producing deadlocks in your application. The 3rd party library (which library?) is probably calling GC.Collect() for some reason. Maybe you can supply some more details?

Upvotes: 4

Matthew Watson
Matthew Watson

Reputation: 109567

You cannot turn off GC in C#/.Net.

However, you can tell it not to run in a separate thread, which possibly may help you:

http://msdn.microsoft.com/en-us/library/at1stbec%28v=vs.100%29.aspx

But is there no way to get the suppliers of the third-party library to fix their crappy code?

Upvotes: 4

Related Questions