<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.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>Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx</link><description>There are several articles around discussing the dispose of SPWeb and SPSite objects, e.g.: SharePoint 2007 and WSS 3.0 Dispose Patterns by Example from Roger Lamb Best Practices: Using Disposable Windows SharePoint Services Objects from Scott Harris</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>The New Definitive SPSite/SPWeb Disposal Article &amp;laquo; Solutionizing .NET</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3164744</link><pubDate>Sun, 07 Dec 2008 07:47:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3164744</guid><dc:creator>The New Definitive SPSite/SPWeb Disposal Article &amp;laquo; Solutionizing .NET</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://solutionizing.net/2008/12/06/the-new-definitive-spsitespweb-disposal-article/"&gt;http://solutionizing.net/2008/12/06/the-new-definitive-spsitespweb-disposal-article/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3164754</link><pubDate>Sun, 07 Dec 2008 09:52:52 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3164754</guid><dc:creator>Jeremy Thake</dc:creator><description>&lt;p&gt;Thanks for this, be great to get this up on the new &lt;a rel="nofollow" target="_new" href="http://www.sharepointdevwiki.com/"&gt;http://www.sharepointdevwiki.com/&lt;/a&gt; Let me know if you’re happy to submit it. That way people can evolve it in a wiki rather than an updated blog post etc. Be interested to hear your thoughts on it Stefan.&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3164763</link><pubDate>Sun, 07 Dec 2008 11:10:51 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3164763</guid><dc:creator>Spence</dc:creator><description>&lt;p&gt;excellent write up mate, thanks!&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3165259</link><pubDate>Mon, 08 Dec 2008 18:55:34 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3165259</guid><dc:creator>Rick</dc:creator><description>&lt;p&gt;Great Post!&lt;/p&gt;
&lt;p&gt;I have one question&lt;/p&gt;
&lt;p&gt;I guess it's ok to dispose in the following situation?&lt;/p&gt;
&lt;p&gt;public override void ItemCheckingOut(SPItemEventProperties properties)&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; SPWeb web = properties.OpenWeb()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; //Do stuff...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; web.dispose();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Cheers, &lt;/p&gt;
&lt;p&gt;Rick&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3165276</link><pubDate>Mon, 08 Dec 2008 19:47:05 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3165276</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Rick,&lt;/p&gt;
&lt;p&gt;yes this call will construct a new SPWeb object which you actually have to dispose.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3166647</link><pubDate>Thu, 11 Dec 2008 06:52:31 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3166647</guid><dc:creator>Keith Dahlby</dc:creator><description>&lt;p&gt;Stefan ~&lt;/p&gt;
&lt;p&gt;Looking at the internals behind the various EventProperties, I'm not finding anywhere that the framework actually cleans up disposable objects allocated to create the child items. SPItemEventProperties is even IDisposable, but Dispose() is never called that I can find.&lt;/p&gt;
&lt;p&gt;Since the SP* objects returned aren't even created until the property is referenced, it seems to me the best practice here would be to create your own SPSite/SPWeb and clean it up yourself. What do you think?&lt;/p&gt;
&lt;p&gt;If this is the case, it's also worth mentioning that SPItemEventProperties.OpenWeb() will internally allocate an SPSite that needs to be cleaned up by the caller.&lt;/p&gt;
&lt;p&gt;Cheers ~&lt;/p&gt;
&lt;p&gt;Keith&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3166704</link><pubDate>Thu, 11 Dec 2008 10:33:16 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3166704</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Keith,&lt;/p&gt;
&lt;p&gt;actually there are two different constructors for SPItemEventProperties.&lt;/p&gt;
&lt;p&gt;One of them passes a SPSite object into the constructor which is then set as the relevant SPSite member variable.&lt;/p&gt;
&lt;p&gt;As the event receiver cannot control how the SPItemEventProperties object has been created it is not allowed to dispose this object as this object might be the SPSite object coming from SPContext (e.g.).&lt;/p&gt;
&lt;p&gt;Regarding IDisposable of SPItemEventProperties: you are right. I just double checked. This looks like a problem in our code. I will forward this info to the right people here.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3167191</link><pubDate>Thu, 11 Dec 2008 23:42:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3167191</guid><dc:creator>Keith Dahlby</dc:creator><description>&lt;p&gt;I agree that it isn't the SPItemEventProperties object's responsibility to dispose of an SPSite that was passed in, which is handled nicely by the logic within Dispose(). Whether or not Dispose() is called is its creator's problem. However, that contract does not exist for SPListEventProperties and SPWebEventProperties, which leads me to believe the auxiliary sites and webs are allowed to leak.&lt;/p&gt;
&lt;p&gt;I'm inclined to mimic the built-in receivers, almost all of which create their own SPSite/SPWeb as necessary and Dispose() when they're done.&lt;/p&gt;
&lt;p&gt;Regards ~&lt;/p&gt;
&lt;p&gt;Keith&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3167192</link><pubDate>Thu, 11 Dec 2008 23:48:21 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3167192</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Keith,&lt;/p&gt;
&lt;p&gt;intersting. I will check into this in more detail tomorrow and post my results.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>Linki do prezentacji o zarządzaniu obiektami</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3169327</link><pubDate>Tue, 16 Dec 2008 01:40:01 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3169327</guid><dc:creator>.neting in the free world</dc:creator><description>&lt;p&gt;Linki, kt&amp;#243;re posłużyły mi przy tworzeniu prezentacji, z kt&amp;#243;rych czerpałem wiedzę, nakładałem ją na to&lt;/p&gt;
</description></item><item><title>WSS 3.0 &amp; MOSS: Recopilatorio de enlaces interesantes (XXIV)!</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3175319</link><pubDate>Thu, 01 Jan 2009 18:28:16 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3175319</guid><dc:creator>Blog del CIIN</dc:creator><description>&lt;p&gt;Un a&amp;#241;o m&amp;#225;s ( &amp;#161;FELIZ A&amp;#209;O NUEVO A TODOS! ), aqu&amp;#237; estoy dando guerra (y ya van m&amp;#225;s de dos desde que Rodrigo&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3177124</link><pubDate>Tue, 06 Jan 2009 22:39:20 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3177124</guid><dc:creator>Keith Dahlby</dc:creator><description>&lt;p&gt;Hey Stefan ~&lt;/p&gt;
&lt;p&gt;I've posted a revision of my disposal article on the SharePoint Dev Wiki here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://sharepointdevwiki.com/display/public/When+to+Dispose+SharePoint+objects"&gt;http://sharepointdevwiki.com/display/public/When+to+Dispose+SharePoint+objects&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I'd appreciate if you could look it over for anything incorrect or omitted.&lt;/p&gt;
&lt;p&gt;Thanks ~&lt;/p&gt;
&lt;p&gt;Keith&lt;/p&gt;</description></item><item><title>try / finally using() SharePoint Dispose()</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182358</link><pubDate>Wed, 14 Jan 2009 17:13:14 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182358</guid><dc:creator>Roger Lamb's SharePoint Developer Blog</dc:creator><description>&lt;p&gt;Chances are that by now if you have been developing on the Microsoft SharePoint Office Server (MOSS)&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182480</link><pubDate>Wed, 14 Jan 2009 20:58:47 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182480</guid><dc:creator>Chirag Patel</dc:creator><description>&lt;p&gt;This is a very nice blog on WSS object disposal and preventing bad memory usage. But What about those web parts that are created using Sharepoint Designer that uses XSLT to render the web part? Do they handle the disposal of SPSite and SPWeb objects internally? &lt;/p&gt;</description></item><item><title>When to Dispose SharePoint objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182691</link><pubDate>Thu, 15 Jan 2009 11:08:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182691</guid><dc:creator>Confluence: SharePoint Development Wiki</dc:creator><description>&lt;p&gt;SPSite and SPWeb implement the IDisposable interface&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182724</link><pubDate>Thu, 15 Jan 2009 12:44:11 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182724</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Chirag,&lt;/p&gt;
&lt;p&gt;not sure which web part you mean in detail but most web parts only use the SPWeb and SPSite objects from SPContext which are not allowed to be disposed.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182841</link><pubDate>Thu, 15 Jan 2009 17:43:47 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182841</guid><dc:creator>Chirag Patel</dc:creator><description>&lt;p&gt;Hi Stefan,&lt;/p&gt;
&lt;p&gt;I am working in a sharepoint project in which there is a root site collection which contains other site collections e.g Info, so there is a data view web part created in SPD which targets the event calendar list which resides in Info site, so it is clear that in any way the SPD data view web part must create an object of Info site collection and get the root web object [this is not SPWeb object created from SPContext site object]. So in such scenario do the SPD data view web part disponses that SPSite and SPWeb objects automatically?&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3182913</link><pubDate>Thu, 15 Jan 2009 19:51:24 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3182913</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Chirag,&lt;/p&gt;
&lt;p&gt;all site collections are independent. A site collection can contain sites - but not site collections.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3183213</link><pubDate>Fri, 16 Jan 2009 04:30:44 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3183213</guid><dc:creator>Keith Dahlby</dc:creator><description>&lt;p&gt;Chirag ~&lt;/p&gt;
&lt;p&gt;Since you're not using code to create the DVWP, you wouldn't have any way to Dispose() the objects even if you wanted to. I would hope the built-in controls would clean up after themselves, but in the worst case scenario since you're only dealing with SPWeb objects from the context SPSite, they will be cleaned up when the context site collection is disposed.&lt;/p&gt;
&lt;p&gt;Keith&lt;/p&gt;</description></item><item><title>To Dispose Or Not To Dispose....That Is The Question</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3190628</link><pubDate>Fri, 23 Jan 2009 07:54:17 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3190628</guid><dc:creator>Tony Testa's World</dc:creator><description>&lt;p&gt;To Dispose Or Not To Dispose....That Is The Question&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3262697</link><pubDate>Fri, 10 Jul 2009 14:24:23 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3262697</guid><dc:creator>Zsolt Borcsok</dc:creator><description>&lt;p&gt;I found this nice problem! An SPRequest, allocated by SPContext.Current, wasn't disposed! How is it possible?&lt;/p&gt;
&lt;p&gt;An SPRequest object was not disposed before the end of this thread. &amp;nbsp;To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. &amp;nbsp;This object will now be disposed. &amp;nbsp;Allocation Id: {42853923-E532-4C15-B002-6BE9D4C6D727} &amp;nbsp;This SPRequest was allocated at &amp;nbsp; &amp;nbsp;at Microsoft.SharePoint.Library.SPRequest..ctor() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous) &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPWeb.InitializeSPRequest() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPWeb.EnsureSPRequest() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPWeb.get_Request() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPWeb.InitWebPublic() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPWeb.get_ID() &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPContext.DefaultKey(HttpContext context, SPWeb web) &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPContext.GetContext(HttpContext context) &amp;nbsp; &amp;nbsp; at Microsoft.SharePoint.SPContext.get_Current() ...&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3262703</link><pubDate>Fri, 10 Jul 2009 15:02:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3262703</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Borcsok,&lt;/p&gt;
&lt;p&gt;looks as if the Microsoft.SharePoint.ApplicationRuntime.SPRequestModule is not registered in the http modules section of the web.config.&lt;/p&gt;
&lt;p&gt;Please double check.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3280052</link><pubDate>Wed, 09 Sep 2009 16:45:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3280052</guid><dc:creator>Kit Menke</dc:creator><description>&lt;p&gt;Stefan,&lt;/p&gt;
&lt;p&gt;If I open an SPWeb and use it to get a SPListItemCollection, does the SPListItemCollection count as a &amp;quot;child object&amp;quot;? If I use that collection after disposing of the SPWeb object that was used to retrieve it, would the SPWeb be reopened?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Kit&lt;/p&gt;
&lt;p&gt;(see my question here for more info &lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/questions/1394952/will-using-a-splistitemcollection-returned-from-a-function-reopen-the-spweb"&gt;http://stackoverflow.com/questions/1394952/will-using-a-splistitemcollection-returned-from-a-function-reopen-the-spweb&lt;/a&gt;)&lt;/p&gt;</description></item><item><title>re: Disposing SPWeb and SPSite objects</title><link>http://blogs.technet.com/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx#3280060</link><pubDate>Wed, 09 Sep 2009 17:11:39 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3280060</guid><dc:creator>Stefan_Gossner</dc:creator><description>&lt;p&gt;Hi Kit,&lt;/p&gt;
&lt;p&gt;yes it can reopen the SPWeb object.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Stefan&lt;/p&gt;
</description></item></channel></rss>