<?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: Disposing of the IDisposable implementation</title> <atom:link href="http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Sun, 20 May 2012 21:55:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Code weave helper for the standard Dispose pattern? &#124; FaceColony.org - Developers Network</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-104605</link> <dc:creator>Code weave helper for the standard Dispose pattern? &#124; FaceColony.org - Developers Network</dc:creator> <pubDate>Sat, 28 Jan 2012 15:22:10 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-104605</guid> <description>[...] You can potentially save yourself a little work by having a base Disposable class like in this blog entry. Then you just have a one-liner at the top of each method: [...]</description> <content:encoded><![CDATA[<p>[...] You can potentially save yourself a little work by having a base Disposable class like in this blog entry. Then you just have a one-liner at the top of each method: [...]</p> ]]></content:encoded> </item> <item><title>By: The Inquisitive Coder - Davy Brion&#8217;s Blog &#187; Blog Archive &#187; The Importance Of Releasing Your Components Through Windsor</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-6407</link> <dc:creator>The Inquisitive Coder - Davy Brion&#8217;s Blog &#187; Blog Archive &#187; The Importance Of Releasing Your Components Through Windsor</dc:creator> <pubDate>Sun, 14 Dec 2008 12:37:56 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-6407</guid> <description>[...] Disposing of the IDisposable implementation [...]</description> <content:encoded><![CDATA[<p>[...] Disposing of the IDisposable implementation [...]</p> ]]></content:encoded> </item> <item><title>By: The Inquisitive Coder - Davy Brion&#8217;s Blog &#187; Blog Archive &#187; .NET Memory Management</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-1173</link> <dc:creator>The Inquisitive Coder - Davy Brion&#8217;s Blog &#187; Blog Archive &#187; .NET Memory Management</dc:creator> <pubDate>Sat, 16 Aug 2008 18:44:40 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-1173</guid> <description>[...] If you can, try to put this pattern into a reusable base class and make your Disposable Managed Resource holding types inherit from this. An example of this approach can be found here. [...]</description> <content:encoded><![CDATA[<p>[...] If you can, try to put this pattern into a reusable base class and make your Disposable Managed Resource holding types inherit from this. An example of this approach can be found here. [...]</p> ]]></content:encoded> </item> <item><title>By: Quantum Bit Designs &#187; Blog Archive &#187; A Thread-Safe IDisposable Base Class</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-845</link> <dc:creator>Quantum Bit Designs &#187; Blog Archive &#187; A Thread-Safe IDisposable Base Class</dc:creator> <pubDate>Wed, 23 Jul 2008 03:48:08 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-845</guid> <description>[...] IDisposable (rarely) we have to look up the recommended pattern. Therefore he came up with an abstract base class that provides the proper plumbing and method signatures. All it takes is deriving from this utility [...]</description> <content:encoded><![CDATA[<p>[...] IDisposable (rarely) we have to look up the recommended pattern. Therefore he came up with an abstract base class that provides the proper plumbing and method signatures. All it takes is deriving from this utility [...]</p> ]]></content:encoded> </item> <item><title>By: Quantum Bit Designs &#187; Blog Archive &#187; A Thread-Safe IDisposable Base Class</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-603</link> <dc:creator>Quantum Bit Designs &#187; Blog Archive &#187; A Thread-Safe IDisposable Base Class</dc:creator> <pubDate>Thu, 10 Jul 2008 11:59:54 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-603</guid> <description>[...] IDisposable (rarely) we have to look up the recommended pattern. Therefore he came up with an abstract base class that provides the proper plumbing and method signatures. All it takes is deriving from this [...]</description> <content:encoded><![CDATA[<p>[...] IDisposable (rarely) we have to look up the recommended pattern. Therefore he came up with an abstract base class that provides the proper plumbing and method signatures. All it takes is deriving from this [...]</p> ]]></content:encoded> </item> <item><title>By: kilfour</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-525</link> <dc:creator>kilfour</dc:creator> <pubDate>Wed, 02 Jul 2008 17:47:10 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-525</guid> <description>To avoid multiple inheritence one could use a nested class that calls the disposing methods in its parent class and return an instance of the nested class from a &lt;i&gt;context initialising&lt;/i&gt; method. Some sort of interface is best defined for the class managing the resources, and an abstract baseclass for the nested class wouldn&#039;t hurt either.
Client code would change from :
&lt;code&gt;
using(MyExpensiveResource resource = new MyExpensiveResource())
{
resource.DoSomething()
}
&lt;/code&gt;
to :
&lt;code&gt;
MyExpensiveResource resource = new MyExpensiveResource()
using(resource.AccessResources())
{
resource.DoSomething()
}
&lt;/code&gt;
AccessResources needs to initialise the resources and return an instance of the nested class that implements idisposable. MyExpensiveResource would probably change name to MyExpensiveResourceManager at this time, but we are discussing a case where the elegant Disposable solution doesn&#039;t work.</description> <content:encoded><![CDATA[<p>To avoid multiple inheritence one could use a nested class that calls the disposing methods in its parent class and return an instance of the nested class from a <i>context initialising</i> method. Some sort of interface is best defined for the class managing the resources, and an abstract baseclass for the nested class wouldn&#8217;t hurt either.<br
/> Client code would change from :<br
/> <code><br
/> using(MyExpensiveResource resource = new MyExpensiveResource())<br
/> {<br
/> resource.DoSomething()<br
/> }<br
/> </code><br
/> to :<br
/> <code><br
/> MyExpensiveResource resource = new MyExpensiveResource()<br
/> using(resource.AccessResources())<br
/> {<br
/> resource.DoSomething()<br
/> }<br
/> </code><br
/> AccessResources needs to initialise the resources and return an instance of the nested class that implements idisposable. MyExpensiveResource would probably change name to MyExpensiveResourceManager at this time, but we are discussing a case where the elegant Disposable solution doesn&#8217;t work.</p> ]]></content:encoded> </item> <item><title>By: Kevin Kerr</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-517</link> <dc:creator>Kevin Kerr</dc:creator> <pubDate>Mon, 30 Jun 2008 02:47:30 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-517</guid> <description>This should have had more kicks :)</description> <content:encoded><![CDATA[<p>This should have had more kicks <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Ayende Rahien</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-516</link> <dc:creator>Ayende Rahien</dc:creator> <pubDate>Sun, 29 Jun 2008 23:13:08 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-516</guid> <description>The full disposable semantics are only required if you are holding an unmanaged resource.
If you are holding only managed resources, you don&#039;t care about that, and can leave the GC to do all the work</description> <content:encoded><![CDATA[<p>The full disposable semantics are only required if you are holding an unmanaged resource.<br
/> If you are holding only managed resources, you don&#8217;t care about that, and can leave the GC to do all the work</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-453</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Sun, 22 Jun 2008 08:59:31 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-453</guid> <description>yeah... code readability is very important to me though, so that&#039;s not a direction i&#039;m willing to take :)inheriting from Disposable works pretty well for me so far... I always try to avoid large inheritance hierarchies, and i only use class inheritance where it makes sense to me.  So i don&#039;t often run into to the issue where i can&#039;t inherit from Disposable.  Unless i have to extend a type i don&#039;t have the source to, but in those cases i prefer composition over inheritance (if possible).</description> <content:encoded><![CDATA[<p>yeah&#8230; code readability is very important to me though, so that&#8217;s not a direction i&#8217;m willing to take <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>inheriting from Disposable works pretty well for me so far&#8230; I always try to avoid large inheritance hierarchies, and i only use class inheritance where it makes sense to me.  So i don&#8217;t often run into to the issue where i can&#8217;t inherit from Disposable.  Unless i have to extend a type i don&#8217;t have the source to, but in those cases i prefer composition over inheritance (if possible).</p> ]]></content:encoded> </item> <item><title>By: Yoram</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-444</link> <dc:creator>Yoram</dc:creator> <pubDate>Sat, 21 Jun 2008 22:52:48 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-444</guid> <description>Here is how I see it:
- the ICleanDisposable doesn&#039;t inherit from IDisposable
- the Disposable aspect implements the IDisposable interface on the aspected class (through a composite aspect with Postsharp)
- In order to call the Dispose() method implemented by the aspect in your code, you will need to use the following method provided by Postsharp:
&lt;code&gt;
K Post.Cast(T myObject)
&lt;/code&gt;Using this method will allow your code to compile. At compilation-time, Postsharp will check if myObject (of type T) can really be casted to the K type (IDisposable in our case).The problem with this approach is that you can&#039;t use the using pattern easily. With the following code:
&lt;code&gt;
// Toto is a class implementing ICleanDisposable and which has the Disposable aspect
using (var toto = Post.Cast(new Toto()))
{
// do something
}
&lt;/code&gt;
you won&#039;t be able to call specific methods on the toto instance, as it will be casted to IDisposable... I guess that if we resort to using an old-school try-finally, we could get it to work as expected, but at the cost of making the code less readable.</description> <content:encoded><![CDATA[<p>Here is how I see it:<br
/> - the ICleanDisposable doesn&#8217;t inherit from IDisposable<br
/> - the Disposable aspect implements the IDisposable interface on the aspected class (through a composite aspect with Postsharp)<br
/> - In order to call the Dispose() method implemented by the aspect in your code, you will need to use the following method provided by Postsharp:<br
/> <code><br
/> K Post.Cast(T myObject)<br
/> </code></p><p>Using this method will allow your code to compile. At compilation-time, Postsharp will check if myObject (of type T) can really be casted to the K type (IDisposable in our case).</p><p>The problem with this approach is that you can&#8217;t use the using pattern easily. With the following code:<br
/> <code><br
/> // Toto is a class implementing ICleanDisposable and which has the Disposable aspect<br
/> using (var toto = Post.Cast(new Toto()))<br
/> {<br
/> // do something<br
/> }<br
/> </code><br
/> you won&#8217;t be able to call specific methods on the toto instance, as it will be casted to IDisposable&#8230; I guess that if we resort to using an old-school try-finally, we could get it to work as expected, but at the cost of making the code less readable.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-422</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 18 Jun 2008 09:52:21 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-422</guid> <description>Actually, that still won&#039;t be perfect... if your type implements the ICleanDisposable interface, you&#039;re still required to provide a Dispose method to fullfil the IDisposable requirements that ICleanDisposable brings with it.If the aspect implements the Dispose method, it won&#039;t be known at compile time since postsharp weaves the aspect code in after it&#039;s been compiled. So you wouldn&#039;t be able to compile to code due to the missing required Dispose method</description> <content:encoded><![CDATA[<p>Actually, that still won&#8217;t be perfect&#8230; if your type implements the ICleanDisposable interface, you&#8217;re still required to provide a Dispose method to fullfil the IDisposable requirements that ICleanDisposable brings with it.</p><p>If the aspect implements the Dispose method, it won&#8217;t be known at compile time since postsharp weaves the aspect code in after it&#8217;s been compiled. So you wouldn&#8217;t be able to compile to code due to the missing required Dispose method</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-421</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 18 Jun 2008 09:38:11 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-421</guid> <description>:)</description> <content:encoded><![CDATA[<p> <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Rob</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-420</link> <dc:creator>Rob</dc:creator> <pubDate>Wed, 18 Jun 2008 09:36:35 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-420</guid> <description>and then we get drunk</description> <content:encoded><![CDATA[<p>and then we get drunk</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-419</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 18 Jun 2008 09:29:16 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-419</guid> <description>ah, so you&#039;d have the type implement the ICleanDisposable interface instead of the IDisposable interface and then from the AOP aspect you&#039;d reference the target class through the interface type and call the DisposeObjects() and ClearReferences() methods at the appropriate time?That would certainly avoid the multiple inheritance issue</description> <content:encoded><![CDATA[<p>ah, so you&#8217;d have the type implement the ICleanDisposable interface instead of the IDisposable interface and then from the AOP aspect you&#8217;d reference the target class through the interface type and call the DisposeObjects() and ClearReferences() methods at the appropriate time?</p><p>That would certainly avoid the multiple inheritance issue</p> ]]></content:encoded> </item> <item><title>By: Rob</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-418</link> <dc:creator>Rob</dc:creator> <pubDate>Wed, 18 Jun 2008 09:24:33 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-418</guid> <description>Maybe something like:&lt;code&gt;
interface ICleanDisposable: IDisposable
{
void DisposeOjects();
void ClearReferences();
}&lt;/code&gt;</description> <content:encoded><![CDATA[<p>Maybe something like:</p><p><code><br
/> interface ICleanDisposable: IDisposable<br
/> {<br
/> void DisposeOjects();<br
/> void ClearReferences();<br
/> }</p><p></code></p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-417</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 18 Jun 2008 09:03:29 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-417</guid> <description>is that a challenge? ;)seriously though, an AOP solution would be nice, but i don&#039;t know how well that would work... you&#039;d have to make your type implement the IDisposable interface (which is possible with the Composite aspect in Postsharp) but then in your aspect you&#039;d have to be able to recognize which members you&#039;d have to dispose. I&#039;m not sure how you could do that without resorting to reflection, which i&#039;d rather not use in a Dispose method</description> <content:encoded><![CDATA[<p>is that a challenge? <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>seriously though, an AOP solution would be nice, but i don&#8217;t know how well that would work&#8230; you&#8217;d have to make your type implement the IDisposable interface (which is possible with the Composite aspect in Postsharp) but then in your aspect you&#8217;d have to be able to recognize which members you&#8217;d have to dispose. I&#8217;m not sure how you could do that without resorting to reflection, which i&#8217;d rather not use in a Dispose method</p> ]]></content:encoded> </item> <item><title>By: Rob</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-416</link> <dc:creator>Rob</dc:creator> <pubDate>Wed, 18 Jun 2008 08:54:20 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-416</guid> <description>I think there still has to be a better way. Maybe some AOP implementation?</description> <content:encoded><![CDATA[<p>I think there still has to be a better way. Maybe some AOP implementation?</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-414</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Wed, 18 Jun 2008 06:44:31 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-414</guid> <description>well, you should dispose each object you contain that implements IDisposable... but yeah, there are a lot of classes that implement that interface without necessarily being that expensive so that name is not really correct.Maybe a simple DisposeObjects() would actually be better?</description> <content:encoded><![CDATA[<p>well, you should dispose each object you contain that implements IDisposable&#8230; but yeah, there are a lot of classes that implement that interface without necessarily being that expensive so that name is not really correct.</p><p>Maybe a simple DisposeObjects() would actually be better?</p> ]]></content:encoded> </item> <item><title>By: Ifeanyi Echeruo</title><link>http://davybrion.com/blog/2008/06/disposing-of-the-idisposable-implementation/comment-page-1/#comment-406</link> <dc:creator>Ifeanyi Echeruo</dc:creator> <pubDate>Tue, 17 Jun 2008 22:16:25 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=147#comment-406</guid> <description>Actually the method name DisposeExpensiveObjects is a bit misleading. Dispose is meant for releasing unmanaged resources; OS handles, network connections etc, they dont have to be expensive just outside the reach of the garbage collector.</description> <content:encoded><![CDATA[<p>Actually the method name DisposeExpensiveObjects is a bit misleading. Dispose is meant for releasing unmanaged resources; OS handles, network connections etc, they dont have to be expensive just outside the reach of the garbage collector.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/39 queries in 0.022 seconds using disk: basic
Object Caching 640/741 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-21 11:54:02 -->
