<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/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>What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx</link><description>I’ve written a few posts about LINQ to SQL and am generally a big fan of the technology (even with its weaknesses) since it’s very productive.&amp;#160; After creating a custom DataContext object using the LINQ to SQL designer (or one created by hand) I always</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6631571</link><pubDate>Thu, 18 Sep 2008 08:39:09 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6631571</guid><dc:creator>Mike</dc:creator><author>Mike</author><description>&lt;p&gt;Disposable != only used in using block. It should be disposed by the object that created it. In a repository pattern, your repositories should share a context (for object tracking to work). So they can&amp;#39;t use the context in a using block. Instead, the context should be made available to them, and should only be disposed if some unit of work is done.&lt;/p&gt;
&lt;p&gt;So if you have to update 1 record A and 2 related records B, only after that is all done, by the same context, can you dispose of it. You could have a context per http request, and an http module to create it and dispose of it at the end of the request cycle.&lt;/p&gt;
&lt;p&gt;Does that make sense, because that&amp;#39;s just my understanding, not &amp;#39;validated&amp;#39; or any thing.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6631571" width="1" height="1"&gt;</description></item><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6546030</link><pubDate>Thu, 21 Aug 2008 07:24:36 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6546030</guid><dc:creator>dwahlin</dc:creator><author>dwahlin</author><description>&lt;p&gt;Paul and Craig,&lt;/p&gt;
&lt;p&gt;Thanks for the additional details. &amp;nbsp;Good stuff with the finalizers (something I haven't had to think much about for awhile). &amp;nbsp;It reenforces the fact that we all need to keep wrapping IDisposable objects in &amp;quot;using&amp;quot; blocks which has always been considered &amp;quot;best practice&amp;quot; anyway.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6546030" width="1" height="1"&gt;</description></item><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6544073</link><pubDate>Wed, 20 Aug 2008 21:41:39 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6544073</guid><dc:creator>PaulWilson</dc:creator><author>PaulWilson</author><description>&lt;p&gt;Here&amp;#39;s the &amp;quot;typically&amp;quot; details:&lt;/p&gt;
&lt;p&gt;The .NET Garbage Collector never ever worries about IDisposable. &amp;nbsp;What it does worry about is finalizers. &amp;nbsp;If an object has a finalizer that hasn&amp;#39;t been suppressed then it won&amp;#39;t be released in the first GC pass. &amp;nbsp;And &amp;quot;typically&amp;quot; objects that implement IDisposable have finalizers, since you probably would want to make sure that your &amp;quot;Dispose&amp;quot; logic is called even if the Dispose method itself is not called. &amp;nbsp;But I&amp;#39;ve seen some IDisposable objects that do not have finalizers, and I think I&amp;#39;ve even seen some in the framework itself when there wasn&amp;#39;t anything really useful in the Dispose method anyhow. &amp;nbsp;But again, you shouldn&amp;#39;t make unnecessary assumptions -- if it implements IDisposable then you should call Dispose (via a using block in most cases), and you should assume it could cost you extra GC cycles if you don&amp;#39;t.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6544073" width="1" height="1"&gt;</description></item><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6543605</link><pubDate>Wed, 20 Aug 2008 19:34:59 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6543605</guid><dc:creator>Craig Stuntz</dc:creator><author>Craig Stuntz</author><description>&lt;p&gt;dwhalin,&lt;/p&gt;
&lt;p&gt;&amp;quot;typically&amp;quot; means that if (1) the type has a Finalize/&amp;quot;destructor&amp;quot; (usually true if implementing IDisposable; it&amp;#39;s part of the pattern) and (2) GC.SuppressFinalize(this) hasn&amp;#39;t been called (generally true if you haven&amp;#39;t called Dispose) then the instance goes into the finalization queue after it becomes unreferenced.&lt;/p&gt;
&lt;p&gt;In other words, it&amp;#39;s an implementation detail. You should presume this is the case unless you know otherwise, and even then it could change later. &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6543605" width="1" height="1"&gt;</description></item><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6542901</link><pubDate>Wed, 20 Aug 2008 16:35:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6542901</guid><dc:creator>dwahlin</dc:creator><author>dwahlin</author><description>&lt;p&gt;Steve,&lt;/p&gt;
&lt;p&gt;Paul only says that he believes any IDisposable object should be disposed of properly and that as developers we shouldn&amp;#39;t worry about the internal workings of objects like DataContext. &amp;nbsp;Having said that, I fully agree with what he says and will continue to wrap &amp;quot;using&amp;quot; statements around the context object. &amp;nbsp;What Steven points out is interesting to know though but definitely subject to change in future releases.&lt;/p&gt;
&lt;p&gt;Craig Stuntz added the following comment to Steven&amp;#39;s blog about what happens if an object isn&amp;#39;t disposed though which is also interesting.&amp;nbsp; The only thing is...he uses the word &amp;quot;typically&amp;quot; which makes me wonder if this always happens or only in some situations:&lt;/p&gt;
&lt;p&gt;&amp;quot;Failing to Dispose an object which implements IDisposable typically results in the object going into the finalization queue (read Chapter 19 of Jeffrey Richter&amp;#39;s Applied Microsoft .NET Framework Programming for details). The results of this is that an object&amp;#39;s memory that might have otherwise been freed in generation 01 be freed until a later generation collection. &amp;nbsp;If you&amp;#39;re creating a lot of these objects, well, do the math.&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Either way...I&amp;#39;m still a fan of explicitly disposing of any object that implements IDisposable so it&amp;#39;s a moot point for me.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6542901" width="1" height="1"&gt;</description></item><item><title>re: What If I Don’t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6542273</link><pubDate>Wed, 20 Aug 2008 12:52:56 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6542273</guid><dc:creator>Steve</dc:creator><author>Steve</author><description>&lt;p&gt;I don&amp;#39;t think he is right this time. &amp;nbsp;See the comment by Paul Wilson.&lt;/p&gt;
&lt;p&gt;I will have to agree here with Paul.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6542273" width="1" height="1"&gt;</description></item><item><title>funny wallpaper &amp;raquo; What If I Don???t Call Dispose() on my LINQ to SQL DataContext Object?</title><link>http://weblogs.asp.net/dwahlin/archive/2008/08/19/what-if-i-don-t-call-dispose-on-my-linq-to-sql-datacontext-object.aspx#6541485</link><pubDate>Wed, 20 Aug 2008 06:11:14 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6541485</guid><dc:creator>funny wallpaper » What If I Don???t Call Dispose() on my LINQ to SQL DataContext Object?</dc:creator><author>funny wallpaper » What If I Don???t Call Dispose() on my LINQ to SQL DataContext Object?</author><description>&lt;p&gt;Pingback from &amp;nbsp;funny wallpaper &amp;amp;raquo; What If I Don???t Call Dispose() on my LINQ to SQL DataContext Object?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6541485" width="1" height="1"&gt;</description></item></channel></rss>