<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Turning off the garbage collector</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx</link><description>It is 
not generally possible to turn off garbage collection. However, the garbage collector won’t run 
unless “provoked.” Garbage collection 
is triggered by: 
 
 1) 
 Allocation 
 2) 
 Explicit calls by the application to 
System.GC.Collect 
 3) 
 Explicit</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title> cbrumme s WebLog Turning off the garbage collector | Insomnia Cure</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#9742651</link><pubDate>Sat, 13 Jun 2009 10:00:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9742651</guid><dc:creator> cbrumme s WebLog Turning off the garbage collector | Insomnia Cure</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://insomniacuresite.info/story.php?id=9170"&gt;http://insomniacuresite.info/story.php?id=9170&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9742651" width="1" height="1"&gt;</description></item><item><title>Memory Not Being Claimed | keyongtech</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#9361119</link><pubDate>Thu, 22 Jan 2009 04:25:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9361119</guid><dc:creator>Memory Not Being Claimed | keyongtech</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.keyongtech.com/2390869-memory-not-being-claimed"&gt;http://www.keyongtech.com/2390869-memory-not-being-claimed&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9361119" width="1" height="1"&gt;</description></item><item><title>Even more on IDisposable</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#397055</link><pubDate>Wed, 16 Mar 2005 23:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:397055</guid><dc:creator>TheChaseMan's Frenetic SoapBox</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=397055" width="1" height="1"&gt;</description></item><item><title>A Few Good GC Links</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#229550</link><pubDate>Tue, 14 Sep 2004 21:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:229550</guid><dc:creator>Chris Lyon's WebLog</dc:creator><description>&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=229550" width="1" height="1"&gt;</description></item><item><title>re: Turning off the garbage collector</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#113120</link><pubDate>Wed, 14 Apr 2004 18:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:113120</guid><dc:creator>Chris Brumme</dc:creator><description>Explicitly collecting is generally a bad idea.  Promotion of short-lived objects into older generations is indeed one of the problems this will cause.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=113120" width="1" height="1"&gt;</description></item><item><title>re: Turning off the garbage collector</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#113067</link><pubDate>Wed, 14 Apr 2004 17:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:113067</guid><dc:creator>David Goldstein</dc:creator><description>This was a debate I started at Code Project...&lt;br&gt;if you explicitly collect, won't you artificially promote short-lived gen0 objects into further generations?&lt;br&gt;&lt;br&gt;davegoldstein@nospam.adelphia.net&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=113067" width="1" height="1"&gt;</description></item><item><title>RE: Turning off the garbage collector</title><link>http://blogs.msdn.com/b/cbrumme/archive/2003/04/15/51319.aspx#51320</link><pubDate>Mon, 05 May 2003 20:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:51320</guid><dc:creator>Chris Brumme</dc:creator><description>Within Microsoft, I occasionally run into teams who are triggering the garbage collector so they can recover a particular instance.

This is a bad idea.

 The GC’s purpose is to efficiently manage resources.  Because of this, GC.Collect &amp;amp; GC.WaitForPendingFinalizers are non-deterministic.

The way to achieve determinism in an application is through IDisposable and similar APIs, not by jiggling the GC.

 One can never predict when the last reference to an object has been released.  Storing a reference to null might be eliminated by the JIT as a dead store.  Depending on register allocation, the lifetime of your reference might be extended to the end of a method.  Depending on how aggressively the JIT is inlining, the lifetime of your reference might be extended to the end of some enclosing method.

 We should not confuse the lifetime of an object’s memory with the semantics we try to achieve inside a Finalize method.  And we should never trigger expensive GCs and draining of the finalizer queue when we are trying to have an impact on a particular object.

 So what is a legitimate use of GC.Collect and GC.WaitForPendingFinalizers?  It is to have a statistical effect on the state of the GC heap.  If you have closed a bunch of windows, or finished a long-running request, or released a ton of cached objects, then calling GC.Collect() might make good sense from a statistical point of view.  But there are no guarantees on whether a particular object will collect.

Along the same lines, a HandleCollector might track the number of outstanding instances of a scarce resource.  If a client requests a new instance and some threshold has been reached, the HandleCollector can trigger a GC and WaitForPendingFinalizers – hoping to reclaim some resources.  But it isn’t making these calls with a goal of reclaiming a particular instance.

If you rely on GC.Collect / WaitForPendingFinalizers to recover a particular instance, your app will certainly be broken as we pursue more aggressive code generation and GC techniques.  (Or perhaps it will just be broken during debugging, or when you run on a non-X86 CPU, or even a machine with more memory).

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=51320" width="1" height="1"&gt;</description></item></channel></rss>