<?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>Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx</link><description>Due to the positive response on my previous entry on Dispose, I thought I'd write another, this time on what one should and shouldn't do with a Dispose method. Dispose should contain code to release any unmanaged resources associated with the object's</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233468</link><pubDate>Thu, 23 Sep 2004 16:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233468</guid><dc:creator>Richard Blewett</dc:creator><description>In terms of ObjectDisposedException I'd argue that you should *always* throw it after a client has called Dispose (other than recalling the Dispose method). They don't know which methods access a resource you release and which don't (unless they have an uhealthy knowledge of your implementation).&lt;br&gt;&lt;br&gt;Dispose to me means &amp;quot;I'm finished with you&amp;quot;. So in that case they have no business calling your methods beyond that point.</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233480</link><pubDate>Thu, 23 Sep 2004 17:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233480</guid><dc:creator>Chris Lyon</dc:creator><description>Hi Richard &lt;br&gt;&lt;br&gt;You could imagine a class that has a property like IsClosed, or a static method that you wouldn't want to throw. Also consider inherited methods (in particular methods that inherit from System.Object, like ToString()).&lt;br&gt;&lt;br&gt;I hesitate to lay down &amp;quot;always do it this way...&amp;quot; rules, because there are always exceptions. </description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233482</link><pubDate>Thu, 23 Sep 2004 17:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233482</guid><dc:creator>Richard Blewett</dc:creator><description>How could you end up in a race condition between the finalizer and dispose? If dispose is running, someone needs to have called it - presumable from a live root. So unless the GC has made a catastrophic error and decided you were garbage when you had a live root; or another object called your Dispose in their Finalizer (which they definitely shouldn't) - how is the Finalizer going to be running at the same time as Dispose?</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233483</link><pubDate>Thu, 23 Sep 2004 17:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233483</guid><dc:creator>Richard Blewett</dc:creator><description>OK - granted about statics - I wouldn't consider statics anyway as they are not involved with the instance being Disposed. But I guess the IsClosed is valid. I suppose I prefer to lay down an absolute and then let people argue why their situation is different ;-)</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233484</link><pubDate>Thu, 23 Sep 2004 17:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233484</guid><dc:creator>Chris Lyon</dc:creator><description>Richard, please read the comments from my previous blog entry and the links to Chris Brumme's blog for an explanation on this race condition.</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233491</link><pubDate>Thu, 23 Sep 2004 17:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233491</guid><dc:creator>Chris Lyon</dc:creator><description>Richard, you probably don't want to throw inside overloaded operators or methods inherited from interfaces, just to name a few more examples.</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233495</link><pubDate>Thu, 23 Sep 2004 17:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233495</guid><dc:creator>Richard Blewett</dc:creator><description>Ugghh - Resurrection&lt;br&gt;&lt;br&gt;Is there actually a useful purpose for resurrection? I have to say its always looked like an abomination to me and so never really been that bright on my radar. &lt;br&gt;&lt;br&gt;I find it slightly perverse to prefer guarding against someone resurrecting my object than against protecting against clean up failure in Dispose. To me the latter is a much more likely scenario and anyone resurrecting my object deserves everything they get ;-)</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233496</link><pubDate>Thu, 23 Sep 2004 17:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233496</guid><dc:creator>Chris Lyon</dc:creator><description>It's clear to me now that I need to dedicate a whole blog entry on resurrection :)&lt;br&gt;&lt;br&gt;Unless resurrection is an expected scenario, guarding against it isn't really necessary (most BCL classes don't).</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233501</link><pubDate>Thu, 23 Sep 2004 17:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233501</guid><dc:creator>Richard Blewett</dc:creator><description>Chris, I can kind of see why throwing in an operator overload would be bizarre for a consumer, but why do you say an interface implementation? What if that implementation accesses the released resource?</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233506</link><pubDate>Thu, 23 Sep 2004 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233506</guid><dc:creator>Chris Lyon</dc:creator><description>Interfaces generally specify behaviour, not implementation, so the Interface is often seperate from the resource. &lt;br&gt;&lt;br&gt;For example, IClomparable.CompareTo shouldn't necessarily throw if the object has been disposed of.&lt;br&gt;&lt;br&gt;Again, these are guidelines, not hard rules.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Dispose Dos and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#233586</link><pubDate>Thu, 23 Sep 2004 20:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:233586</guid><dc:creator>Richard Blewett</dc:creator><description>Agreed that interface define behaviour, but the issue is whether the implementation can satisfy that behaviour once Dispose has been called. But as you say - they are only guidelines (have you seen Pirates of the Caribbean? ;-) )&lt;br&gt;&lt;br&gt;I'm looking forward to your blog post on resurrection - it will be interesting to here about the BCL classes that have been built with it in mind.</description></item><item><title>Dispose Do's and Don'ts</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#235021</link><pubDate>Tue, 28 Sep 2004 05:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:235021</guid><dc:creator>OdeToCode Link Blog</dc:creator><description /></item><item><title>Disposable Object</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#236084</link><pubDate>Thu, 30 Sep 2004 13:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:236084</guid><dc:creator>Managed from down under</dc:creator><description>Describes a base class for disposable objects.</description></item><item><title>Disposable Object</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#236085</link><pubDate>Thu, 30 Sep 2004 13:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:236085</guid><dc:creator>Managed from down under</dc:creator><description>Describes a base class for disposable objects.</description></item><item><title>Disposable Object</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#236087</link><pubDate>Thu, 30 Sep 2004 13:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:236087</guid><dc:creator>Managed from down under</dc:creator><description>Describes a base class for disposable objects.</description></item><item><title>More on Garbage Collection</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#237014</link><pubDate>Sat, 02 Oct 2004 20:57:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:237014</guid><dc:creator>Rob Windsor's Weblog</dc:creator><description /></item><item><title> Chris Lyon s WebLog Dispose Dos and Don ts |  Hammock Stand</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#9689287</link><pubDate>Wed, 03 Jun 2009 07:38:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9689287</guid><dc:creator> Chris Lyon s WebLog Dispose Dos and Don ts |  Hammock Stand</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://hammockstandsite.info/story.php?id=18314"&gt;http://hammockstandsite.info/story.php?id=18314&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Chris Lyon s WebLog Dispose Dos and Don ts | storage bench</title><link>http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx#9782635</link><pubDate>Fri, 19 Jun 2009 11:05:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9782635</guid><dc:creator> Chris Lyon s WebLog Dispose Dos and Don ts | storage bench</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://thestoragebench.info/story.php?id=5028"&gt;http://thestoragebench.info/story.php?id=5028&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>