<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Disposing list&#8217;s SPSite/SPWeb without ParentWeb</title>
	<atom:link href="http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/feed/" rel="self" type="application/rss+xml" />
	<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/</link>
	<description>Random thoughts on custom development in SharePoint.</description>
	<lastBuildDate>Fri, 06 Jan 2012 00:13:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Keith Dahlby</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-74</link>
		<dc:creator><![CDATA[Keith Dahlby]]></dc:creator>
		<pubDate>Sat, 01 Nov 2008 16:34:39 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-74</guid>
		<description><![CDATA[You&#039;ve discovered the fundamental issue with the current implementation of Dispose(): The objects are closed and marked as invalid, &lt;strong&gt;but they still work&lt;/strong&gt;. However, behavior of an IDisposable after it has been disposed is technically undefined. While the code might seem to work 99% of the time, there is absolutely no guarantee that it will always work.

Regarding returning an SPListItem or SPFile, I think you have to assume they might need a reference to their parent Web at any time. So you should either extract the data you need into a non-SP object (DataTable, custom business object, anonymous type in 3.5), or find a way to Dispose later. Ultimately, you should only dispose if you&#039;re 100% certain the reference will never be used again.]]></description>
		<content:encoded><![CDATA[<p>You&#8217;ve discovered the fundamental issue with the current implementation of Dispose(): The objects are closed and marked as invalid, <strong>but they still work</strong>. However, behavior of an IDisposable after it has been disposed is technically undefined. While the code might seem to work 99% of the time, there is absolutely no guarantee that it will always work.</p>
<p>Regarding returning an SPListItem or SPFile, I think you have to assume they might need a reference to their parent Web at any time. So you should either extract the data you need into a non-SP object (DataTable, custom business object, anonymous type in 3.5), or find a way to Dispose later. Ultimately, you should only dispose if you&#8217;re 100% certain the reference will never be used again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Challen</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-73</link>
		<dc:creator><![CDATA[Andrew Challen]]></dc:creator>
		<pubDate>Sat, 01 Nov 2008 09:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-73</guid>
		<description><![CDATA[What I&#039;m still struggling to get my head round is that even if you move the 
webToDispose.Dispose();
webToDispose.Site.Dispose();
to inside the getList method; when the foreach on the returned SPList doesn&#039;t fail.  What&#039;s more is that if I compare the hash code before my premature dispose and after the for each they are the same, why?  I have a few ideas but don&#039;t know how to find out which is right yet. 

Secondly if I return a SPListItem or SPListItem.File etc. do I still need to dispose of the SPSite and SPWeb only after I&#039;ve used them?]]></description>
		<content:encoded><![CDATA[<p>What I&#8217;m still struggling to get my head round is that even if you move the<br />
webToDispose.Dispose();<br />
webToDispose.Site.Dispose();<br />
to inside the getList method; when the foreach on the returned SPList doesn&#8217;t fail.  What&#8217;s more is that if I compare the hash code before my premature dispose and after the for each they are the same, why?  I have a few ideas but don&#8217;t know how to find out which is right yet. </p>
<p>Secondly if I return a SPListItem or SPListItem.File etc. do I still need to dispose of the SPSite and SPWeb only after I&#8217;ve used them?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Dahlby</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-72</link>
		<dc:creator><![CDATA[Keith Dahlby]]></dc:creator>
		<pubDate>Fri, 31 Oct 2008 14:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-72</guid>
		<description><![CDATA[I agree that this approach isn&#039;t pretty, it was just one of my first investigations into this issue. I prefer the pattern described in my post &quot;SPSite/SPWeb Leaks Revisited&quot;, though the initial example is still rather contrived. Ultimately there are several correct solutions, depending on what you need from the objects in question. Just be careful returning any SharePoint object from a function in which its parent web (or site) has been disposed. If you&#039;re caching a DataTable as recommended, you shouldn&#039;t have much to worry about.]]></description>
		<content:encoded><![CDATA[<p>I agree that this approach isn&#8217;t pretty, it was just one of my first investigations into this issue. I prefer the pattern described in my post &#8220;SPSite/SPWeb Leaks Revisited&#8221;, though the initial example is still rather contrived. Ultimately there are several correct solutions, depending on what you need from the objects in question. Just be careful returning any SharePoint object from a function in which its parent web (or site) has been disposed. If you&#8217;re caching a DataTable as recommended, you shouldn&#8217;t have much to worry about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Challen</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-71</link>
		<dc:creator><![CDATA[Andrew Challen]]></dc:creator>
		<pubDate>Fri, 31 Oct 2008 12:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-71</guid>
		<description><![CDATA[I&#039;d not tired executing it! My feeling is that 
private SPList getList(out SPWeb webToDispose)
is dangerous though as you need to remember to know what to do with webToDispose perhaps out 
I think I&#039;d rather see
private SPList getList(out object[] objectsToDispose)
I&#039;m still thinking that I&#039;d rather see neither
For my task I&#039;m going to try using similar idea to the CacheData function here 
http://msdn.microsoft.com/en-us/library/bb687949.aspx]]></description>
		<content:encoded><![CDATA[<p>I&#8217;d not tired executing it! My feeling is that<br />
private SPList getList(out SPWeb webToDispose)<br />
is dangerous though as you need to remember to know what to do with webToDispose perhaps out<br />
I think I&#8217;d rather see<br />
private SPList getList(out object[] objectsToDispose)<br />
I&#8217;m still thinking that I&#8217;d rather see neither<br />
For my task I&#8217;m going to try using similar idea to the CacheData function here<br />
<a href="http://msdn.microsoft.com/en-us/library/bb687949.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb687949.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Dahlby</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-70</link>
		<dc:creator><![CDATA[Keith Dahlby]]></dc:creator>
		<pubDate>Thu, 30 Oct 2008 17:51:27 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-70</guid>
		<description><![CDATA[The site is disposed at the end of DoSomething():

  if (webToDispose != null) {
    webToDispose.Dispose();
    webToDispose.Site.Dispose(); // &lt;--
  }

The site can&#039;t be disposed within getList because disposing an SPSite also disposes all webs opened from it, including the web we need to leave open.]]></description>
		<content:encoded><![CDATA[<p>The site is disposed at the end of DoSomething():</p>
<p>  if (webToDispose != null) {<br />
    webToDispose.Dispose();<br />
    webToDispose.Site.Dispose(); // &lt;&#8211;<br />
  }</p>
<p>The site can&#8217;t be disposed within getList because disposing an SPSite also disposes all webs opened from it, including the web we need to leave open.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Challen</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-69</link>
		<dc:creator><![CDATA[Andrew Challen]]></dc:creator>
		<pubDate>Thu, 30 Oct 2008 17:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-69</guid>
		<description><![CDATA[SPSite site = new SPSite(&quot;http://solutionizing.net&quot;);

shouldn&#039;t you dispose the site too?

i.e.

using(SPSite site = new SPSite(&quot;http://solutionizing.net&quot;)){
    webToDispose = site.OpenWeb(&quot;/MyWeb&quot;);
    list = webToDispose.Lists[&quot;MyList&quot;];
}]]></description>
		<content:encoded><![CDATA[<p>SPSite site = new SPSite(&#8220;http://solutionizing.net&#8221;);</p>
<p>shouldn&#8217;t you dispose the site too?</p>
<p>i.e.</p>
<p>using(SPSite site = new SPSite(&#8220;http://solutionizing.net&#8221;)){<br />
    webToDispose = site.OpenWeb(&#8220;/MyWeb&#8221;);<br />
    list = webToDispose.Lists["MyList"];<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Is SPList.ParentWeb a Leak? &#171; Solutionizing .NET</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-39</link>
		<dc:creator><![CDATA[Is SPList.ParentWeb a Leak? &#171; Solutionizing .NET]]></dc:creator>
		<pubDate>Sun, 10 Aug 2008 05:39:20 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-39</guid>
		<description><![CDATA[[...] SPList.ParentWeb a&#160;Leak? August 10, 2008 &#8212; Keith Dahlby   As previously discussed, doing the &#8220;right thing&#8221; with our SPSite and SPWeb references&#8217; [...]]]></description>
		<content:encoded><![CDATA[<p>[...] SPList.ParentWeb a&nbsp;Leak? August 10, 2008 &#8212; Keith Dahlby   As previously discussed, doing the &#8220;right thing&#8221; with our SPSite and SPWeb references&#8217; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SPSite/SPWeb Leaks Revisited &#171; Solutionizing .NET</title>
		<link>http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/#comment-20</link>
		<dc:creator><![CDATA[SPSite/SPWeb Leaks Revisited &#171; Solutionizing .NET]]></dc:creator>
		<pubDate>Wed, 23 Jul 2008 06:50:08 +0000</pubDate>
		<guid isPermaLink="false">http://solutionizing.wordpress.com/?p=7#comment-20</guid>
		<description><![CDATA[[...] Leaks&#160;Revisited July 23, 2008 &#8212; Keith Dahlby   A while back I posted a rather clumsy technique to mitigate an SPWeb leak discussed here. I knew there had to be a better way, and Rob [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Leaks&nbsp;Revisited July 23, 2008 &#8212; Keith Dahlby   A while back I posted a rather clumsy technique to mitigate an SPWeb leak discussed here. I knew there had to be a better way, and Rob [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

