<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Compiler Enforced Disposal?</title>
	<atom:link href="http://davybrion.com/blog/2008/11/compiler-enforced-disposal/feed/" rel="self" type="application/rss+xml" />
	<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/</link>
	<description>Trying to walk that thin line between intelligence and ignorance</description>
	<lastBuildDate>Thu, 11 Mar 2010 23:14:12 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5162</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Tue, 18 Nov 2008 12:09:44 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5162</guid>
		<description>nope, there is no real drawback to calling Dispose() methods that aren&#039;t really required. The only &#039;drawback&#039; is that it&#039;s just more code than is needed.</description>
		<content:encoded><![CDATA[<p>nope, there is no real drawback to calling Dispose() methods that aren&#8217;t really required. The only &#8216;drawback&#8217; is that it&#8217;s just more code than is needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Wiebe</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5161</link>
		<dc:creator>Jeremy Wiebe</dc:creator>
		<pubDate>Tue, 18 Nov 2008 12:05:23 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5161</guid>
		<description>I agree with Den Ben also... I&#039;d add that having the compiler enforce disposal would be difficult to get right.  For instance, I usually say that the class that creates should be the class that Dispose()es.  There&#039;s a whole bunch of situations where a class may have a reference to an IDisposable, but should not be the one Dispose()ing it.  This would be especially true for objects created through an IoC container.

Also, is there any severe drawback to calling Dispose() on classes that don&#039;t require it (other than having a few extra using() blocks around)?</description>
		<content:encoded><![CDATA[<p>I agree with Den Ben also&#8230; I&#8217;d add that having the compiler enforce disposal would be difficult to get right.  For instance, I usually say that the class that creates should be the class that Dispose()es.  There&#8217;s a whole bunch of situations where a class may have a reference to an IDisposable, but should not be the one Dispose()ing it.  This would be especially true for objects created through an IoC container.</p>
<p>Also, is there any severe drawback to calling Dispose() on classes that don&#8217;t require it (other than having a few extra using() blocks around)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neal Blomfield</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5127</link>
		<dc:creator>Neal Blomfield</dc:creator>
		<pubDate>Mon, 17 Nov 2008 19:27:39 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5127</guid>
		<description>I have to agree with Den Ben.  An interface is a contract that explicitly defines the interaction between client and server.  If something is implementing IDisposable and it doesn&#039;t need disposing 2 things should happen:
1.  Remove IDisposable from the list of interfaces the class implements and marked the Dispose method with [Obsolete]
2.  Find the developer(s) that made the choice to mark classes not requiring disposal with IDisposable and whack them across the knuckles with a steel rule (my old woodwork teachers favourite method of making a lesson out of a poorly chosen action)

=)</description>
		<content:encoded><![CDATA[<p>I have to agree with Den Ben.  An interface is a contract that explicitly defines the interaction between client and server.  If something is implementing IDisposable and it doesn&#8217;t need disposing 2 things should happen:<br />
1.  Remove IDisposable from the list of interfaces the class implements and marked the Dispose method with [Obsolete]<br />
2.  Find the developer(s) that made the choice to mark classes not requiring disposal with IDisposable and whack them across the knuckles with a steel rule (my old woodwork teachers favourite method of making a lesson out of a poorly chosen action)</p>
<p>=)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Van Ryswyck</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5117</link>
		<dc:creator>Jan Van Ryswyck</dc:creator>
		<pubDate>Mon, 17 Nov 2008 15:17:48 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5117</guid>
		<description>If C# finally gets those compiler hooks (as Anders promised) the same way like the Boo compiler supports them, then you can role out your own mechanism. Alas I think this is a C# 5.0 feature :-(</description>
		<content:encoded><![CDATA[<p>If C# finally gets those compiler hooks (as Anders promised) the same way like the Boo compiler supports them, then you can role out your own mechanism. Alas I think this is a C# 5.0 feature <img src='http://davybrion.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan Van Ryswyck</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5111</link>
		<dc:creator>Jan Van Ryswyck</dc:creator>
		<pubDate>Mon, 17 Nov 2008 14:30:33 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5111</guid>
		<description>I like the idea.</description>
		<content:encoded><![CDATA[<p>I like the idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dew Drop - November 17, 2008 &#124; Alvin Ashcraft's Morning Dew</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5108</link>
		<dc:creator>Dew Drop - November 17, 2008 &#124; Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Mon, 17 Nov 2008 12:57:24 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5108</guid>
		<description>[...] Compiler Enforced Disposal? (Davy Brion) [...]</description>
		<content:encoded><![CDATA[<p>[...] Compiler Enforced Disposal? (Davy Brion) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5106</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Mon, 17 Nov 2008 11:28:48 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5106</guid>
		<description>good point about it not always been clear wether or not we&#039;re dealing with an instance that has the attribute or not

and yeah, if Microsoft had been very clear about the IDisposable interface/contract from the start, and if everyone had followed the conventions than all of this wouldn&#039;t have been such a big deal... but the way it is now with all the confusion and the conflicting advice is just terrible. Especially when some BCL developers even think you should just rely on finalization... that is just wrong on so many levels IMHO</description>
		<content:encoded><![CDATA[<p>good point about it not always been clear wether or not we&#8217;re dealing with an instance that has the attribute or not</p>
<p>and yeah, if Microsoft had been very clear about the IDisposable interface/contract from the start, and if everyone had followed the conventions than all of this wouldn&#8217;t have been such a big deal&#8230; but the way it is now with all the confusion and the conflicting advice is just terrible. Especially when some BCL developers even think you should just rely on finalization&#8230; that is just wrong on so many levels IMHO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cornelius Gouws</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5105</link>
		<dc:creator>Cornelius Gouws</dc:creator>
		<pubDate>Mon, 17 Nov 2008 11:20:36 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5105</guid>
		<description>The problem with adding an attribute to force the compiler to throw compile time exceptions is that the compiler cannot always know if the attribute is there.
If you have a method:
&lt;code&gt;
private IDisposable GetObject(bool b)
{
// Return an IDisposable that is marked with 
// the RequiresDisposal attribute if b is true 
// else an IDisposable that is not marked with 
// the RequiresDisposal attribute.
}
&lt;/code&gt;
Then if the GetObject method is invoked the compiler would not be able to see if the RequiresDisposal attribute is present and will at best throw a Runtime exception.

But as you mentioned if the use of the IDisposable has been standardized from the start (and those standards actually followed) we would not be sitting with this issue now.</description>
		<content:encoded><![CDATA[<p>The problem with adding an attribute to force the compiler to throw compile time exceptions is that the compiler cannot always know if the attribute is there.<br />
If you have a method:<br />
<code><br />
private IDisposable GetObject(bool b)<br />
{<br />
// Return an IDisposable that is marked with<br />
// the RequiresDisposal attribute if b is true<br />
// else an IDisposable that is not marked with<br />
// the RequiresDisposal attribute.<br />
}<br />
</code><br />
Then if the GetObject method is invoked the compiler would not be able to see if the RequiresDisposal attribute is present and will at best throw a Runtime exception.</p>
<p>But as you mentioned if the use of the IDisposable has been standardized from the start (and those standards actually followed) we would not be sitting with this issue now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Davy Brion</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5076</link>
		<dc:creator>Davy Brion</dc:creator>
		<pubDate>Sun, 16 Nov 2008 21:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5076</guid>
		<description>well, i thought of the attribute to distinguish between IDisposables where it&#039;s not that important that you dispose of them, and IDisposables where you really, really should.

I know that a lot of IDisposables still call Dispose in their Finalizer method if the object hasn&#039;t been Disposed of so you could argue that there are _no_ IDisposables that really require being Disposed of. But Finalizers can lead to other performance issues, so i don&#039;t think that all IDisposables actually use that approach.</description>
		<content:encoded><![CDATA[<p>well, i thought of the attribute to distinguish between IDisposables where it&#8217;s not that important that you dispose of them, and IDisposables where you really, really should.</p>
<p>I know that a lot of IDisposables still call Dispose in their Finalizer method if the object hasn&#8217;t been Disposed of so you could argue that there are _no_ IDisposables that really require being Disposed of. But Finalizers can lead to other performance issues, so i don&#8217;t think that all IDisposables actually use that approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: den Ben</title>
		<link>http://davybrion.com/blog/2008/11/compiler-enforced-disposal/comment-page-1/#comment-5074</link>
		<dc:creator>den Ben</dc:creator>
		<pubDate>Sun, 16 Nov 2008 21:23:20 +0000</pubDate>
		<guid isPermaLink="false">http://davybrion.com/blog/?p=585#comment-5074</guid>
		<description>I like the idea of a compiler enforcing the disposing of IDisposable objects.  However, I think the fact that an object implements IDisposable should be enough as is.  I do not see any reasons to introduce a RequiresDisposal attribute for that.</description>
		<content:encoded><![CDATA[<p>I like the idea of a compiler enforcing the disposing of IDisposable objects.  However, I think the fact that an object implements IDisposable should be enough as is.  I do not see any reasons to introduce a RequiresDisposal attribute for that.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
