<?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>Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx</link><description>In concurrent programs, race conditions are a fact of life but they aren’t all bad.&amp;#160; Sometimes, race conditions are benign, as is often the case with lazy initialization.&amp;#160; The problem with racing to set a value, however, is that it can result</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9804688</link><pubDate>Fri, 26 Jun 2009 06:15:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9804688</guid><dc:creator>Joe Albahari</dc:creator><description>&lt;p&gt;Shouldn't EnsureInitialized be overloaded to provide this disposal behaviour as an option?&lt;/p&gt;
&lt;p&gt;If you make this an option, it will yield greater benefit than just convenience. When people see the disposeUnusedObject parameter in IntelliSense, they'll be forced to think about the problem - which is surely a good thing!&lt;/p&gt;
&lt;p&gt;Otherwise, all but the most astute people will be unaware that the problem exists and will leave undisposed objects at the mercy of the GC's schedule. Which is OK with wait handles (which have a low OS burden), but not so cool with file handles (which can block access to the file!)&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9805126</link><pubDate>Fri, 26 Jun 2009 12:14:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9805126</guid><dc:creator>Kristian Freed</dc:creator><description>&lt;p&gt;Nice posting!&lt;/p&gt;
&lt;p&gt;I think ownership of objects is something people spend much too little time thinking about (and documenting!) when it comes to garbage collected languages in general. In C++ for example, you need to be explicitly aware of who owns an object much more often, because someone is responsible for deallocating it at some point. Removing the need to explicitly free objects from memory also gives the illusion that all other questions of ownership (May I change this object I received from somewhere else, or do I have to make a copy? Can it change while I'm using it? &amp;nbsp;May/should I dispose of it when I'm done with it myself?) have been resolved automatically as well.&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9805583</link><pubDate>Fri, 26 Jun 2009 18:17:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9805583</guid><dc:creator>phillips.joshua</dc:creator><description>&lt;p&gt;Hi Joe,&lt;/p&gt;
&lt;p&gt;Ideally, yes. &amp;nbsp;This is exactly what we had hoped to do. &amp;nbsp;Unfortunately, the harsh reality of shipping a product is that sometime you have to, well, ship.. And to do that, we have to stop churning code at some point. &amp;nbsp;Given that this API is really advanced and we don't expect many mainstream developers to use it (they'd use Lazy&amp;lt;T&amp;gt; instead) we decided not to prioritize adding an overload. &amp;nbsp;Those that will use it, are likely to be very concerned with things like file handles and make sure they're disposed properly.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Josh&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9805605</link><pubDate>Fri, 26 Jun 2009 18:34:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9805605</guid><dc:creator>Tom Kirby-Green</dc:creator><description>&lt;p&gt;I would concur with Kristian's point, a lot of developers seems to mentally broaden the GC's remit from 'memory' to 'general responsibility' collector. Gosh how I wish I could declare a const reference to a object in C# ...&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9814413</link><pubDate>Thu, 02 Jul 2009 19:21:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9814413</guid><dc:creator>Nicholas Paldino [.NET/C# MVP]</dc:creator><description>&lt;p&gt;Shouldn't the call to compare be to ReferenceEquals on Object? &amp;nbsp;If for some reason, compare-by-value semantics has been implemented in the equality operator (which best practice indicates you should implement != as well), then there is an issue of disposing the wrong object here.&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9821100</link><pubDate>Tue, 07 Jul 2009 04:12:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9821100</guid><dc:creator>phillips.joshua</dc:creator><description>&lt;p&gt;Hi Nicholas,&lt;/p&gt;
&lt;p&gt;Good question. In most cases, that would be true, but in this case, the restrictions on generics actually helps(?) out here. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;In C# overloading operators on generic types is not supported and thus inside of the generic method, != will not resolve to the overriden implementation. &amp;nbsp;You do have a good argument for readability, however!&lt;/p&gt;
&lt;p&gt;Josh&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9859286</link><pubDate>Thu, 06 Aug 2009 18:55:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9859286</guid><dc:creator>Duarte Nunes</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Indeed, object ownership is an issue with the disposable pattern, which is why the right thing to do is indeed to let the user deal with object disposal (or provide an explicit overload).&lt;/p&gt;
&lt;p&gt;Also, I was looking at the beta 1 code for LazyInitializer and noticed that you use an acquire barrier on the public methods, but I can't seem to figure out what it's for, with my understanding of the memory model (is there going to be a formal memory model specification, based on Prism?).&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Duarte&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9859493</link><pubDate>Thu, 06 Aug 2009 21:56:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9859493</guid><dc:creator>phillips.joshua</dc:creator><description>&lt;p&gt;Hi Duarte,&lt;/p&gt;
&lt;p&gt;We read a dummy volatile variable to prevent potential memory reordering in IA64. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;Josh&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9859518</link><pubDate>Thu, 06 Aug 2009 22:26:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9859518</guid><dc:creator>Duarte Nunes</dc:creator><description>&lt;p&gt;Hi Josh,&lt;/p&gt;
&lt;p&gt;Thanks for the answer! I guess you mean the potential load-load reordering. Does this mean the memory model for 4.0 that we developers must address is the weakest (i.e., IA64's)?&lt;/p&gt;
&lt;p&gt;Thanks again,&lt;/p&gt;
&lt;p&gt;Duarte&lt;/p&gt;
</description></item><item><title>re: Don’t dispose of objects that you don’t own</title><link>http://blogs.msdn.com/pfxteam/archive/2009/06/24/9802337.aspx#9859520</link><pubDate>Thu, 06 Aug 2009 22:33:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9859520</guid><dc:creator>phillips.joshua</dc:creator><description>&lt;p&gt;That, of course, depends on the architecture(s) you are targeting. :) &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Josh&lt;/p&gt;
</description></item></channel></rss>