Disable garbage collection?

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Is it possible to disable garbage collection for a limited period of time
during a critical section of code? I did find the gcConcurrent runtime
setting, but from what I read, it can still halt your application. Our app
has a requirement to send a command in a specified period of time from the
press of a button. I want to ensure that GC does not get kicked off during
that time the button press event is active.
 
Hi Bob

No you can't disable the Garbage Collector. The best you can do is before your critcal code, force a collection, then drain the finalizer queue, like this:

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
// critical code

This will NOT guarantee a collection won't occur, but it minimizes the chance.

Hope that helps
-Chris


--------------------
From: "Bob" <[email protected]>
Subject: Disable garbage collection?
Date: Mon, 15 Mar 2004 12:10:26 -0800
Lines: 8
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: blv-gate-01.boeing.com 130.76.32.64
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:127965
X-Tomcat-NG: microsoft.public.dotnet.general

Is it possible to disable garbage collection for a limited period of time
during a critical section of code? I did find the gcConcurrent runtime
setting, but from what I read, it can still halt your application. Our app
has a requirement to send a command in a specified period of time from the
press of a button. I want to ensure that GC does not get kicked off during
that time the button press event is active.


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
 
If your critical code doesn't allocate any memory (or as little as
possible), then it's highly likely the GC won't fire.

Are you getting a collect within this code? If so how long is the collection
taking, that it interferes with this code?
 
Stu,

Keep in mind, if the application is multithreaded, allocations on another thread may force a collection. Also, since the finalization is automatic (and non-deterministic), the
finalizer thread may be run during peformace-critical code, unless the finalization queue is first drained.

-Chris

--------------------
From: "Stu Smith" <[email protected]>
References: <[email protected]>
Subject: Re: Disable garbage collection?
Date: Tue, 16 Mar 2004 14:33:30 -0000
Lines: 21
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 81.171.142.210
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:128058
X-Tomcat-NG: microsoft.public.dotnet.general

If your critical code doesn't allocate any memory (or as little as
possible), then it's highly likely the GC won't fire.

Are you getting a collect within this code? If so how long is the collection
taking, that it interferes with this code?


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
 
Back
Top