<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-4126985520350746834.post5886455956126422450..comments</id><updated>2011-08-24T06:49:56.932+01:00</updated><category term='Personal'/><category term='Coding'/><category term='WCM'/><category term='Continuous Integration'/><category term='jQuery'/><category term='master pages'/><category term='debugging'/><category term='workflow'/><category term='speaking'/><category term='page layouts'/><category term='security'/><category term='lists'/><category term='deployment'/><category term='SharePoint'/><category term='AJAX'/><category term='content deployment'/><category term='ghosting'/><category term='codeplex'/><category term='help'/><category term='TechEd'/><category term='customizing'/><category term='Virtual Server'/><category term='CAS policy'/><category term='site definitions'/><category term='user group'/><category term='CustomAction'/><category term='SP2010'/><category term='feature-stapling'/><category term='Content Deployment Wizard'/><category term='webparts'/><category term='feature receiver'/><category term='site columns'/><category term='configuration'/><category term='features'/><category term='central admin'/><category term='DelegateControl'/><category term='MOSS'/><category term='content migration API'/><category term='VSeWSS'/><category term='Virtual Machine Manager'/><category term='content query web part'/><category term='content types'/><category term='InfoPath'/><title type='text'>Comments on Chris O'Brien: Disposing SharePoint objects - what they don't tel...</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.sharepointnutsandbolts.com/feeds/5886455956126422450/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default'/><link rel='alternate' type='text/html' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html'/><author><name>Chris O'Brien</name><uri>http://www.blogger.com/profile/10022906552670607366</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_DPonmXhJQ4g/SiFZBcX_Q1I/AAAAAAAAAa0/14b7VTN0FZM/s1600-R/28f5735.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4126985520350746834.post-5475962463782521827</id><published>2008-06-16T12:27:00.000+01:00</published><updated>2008-06-16T12:27:00.000+01:00</updated><title type='text'>Interesting comments - these are good contribution...</title><content type='html'>Interesting comments - these are good contributions, thanks.&lt;BR/&gt;&lt;BR/&gt;Keith - I like your idea, it's a nice alternative to my suggestion. One drawback however is it works well for a small call stack (like my example), but similar to Tojonas' comment, not so well for a more complex pattern - you'd need to pass your out parameter around between methods/classes. This is avoided to a certain extent in my structure, where you only need the SPList/SPListItem which you could be passing around for actual use.&lt;BR/&gt;&lt;BR/&gt;Still, I'm not sure either is a real solution to the deeper problem Jonas points out very well. I'm not sure I'd go as far as to say the OM is broken, but it sure is tricky to write library code around the API. Jonas, if you give any further consideration to your layer I'd be interested to hear more, but I can also see there could be interesting issues around class responsiblity there. &lt;BR/&gt;&lt;BR/&gt;I have a follow-up post which expands on these kind of issues soon.&lt;BR/&gt;&lt;BR/&gt;Chris.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/5475962463782521827'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/5475962463782521827'/><link rel='alternate' type='text/html' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html?showComment=1213615620000#c5475962463782521827' title=''/><author><name>Chris O'Brien</name><uri>http://www.blogger.com/profile/10022906552670607366</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html' ref='tag:blogger.com,1999:blog-4126985520350746834.post-5886455956126422450' source='http://www.blogger.com/feeds/4126985520350746834/posts/default/5886455956126422450' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2092051249'/></entry><entry><id>tag:blogger.com,1999:blog-4126985520350746834.post-8068833809825688165</id><published>2008-06-16T08:59:00.000+01:00</published><updated>2008-06-16T08:59:00.000+01:00</updated><title type='text'>Thanks for a good post.&lt;br&gt;&lt;br&gt;The problem is that...</title><content type='html'>Thanks for a good post.&lt;BR/&gt;&lt;BR/&gt;The problem is that this doesn't scale at all.&lt;BR/&gt;&lt;BR/&gt;You have already touched on the problem of writing LIBRARY code for SharePoint, and that is what I'm talking about below.&lt;BR/&gt;&lt;BR/&gt;In my opinion it's IMPOSSIBLE to do it "correct" since sometimes you should dispose of objects and sometimes you shouldn't. (Remember that I'm talking about library code where the method has no knowledge about how the SPWeb and SPSite was constructed)&lt;BR/&gt;&lt;BR/&gt;&lt;BR/&gt;The deeper your call stack gets the more impossible it gets.&lt;BR/&gt;&lt;BR/&gt;In your example you only have two levels. Your main method and then you get the objects using two helper methods. And you had to intoduce a flag to know when to dispose or not.&lt;BR/&gt;&lt;BR/&gt;Just imagine that you have more nested calls and you see it can't be done.&lt;BR/&gt;&lt;BR/&gt;The reason I say it can't be done is that we have been told that just by accessing some &lt;A HREF="http://blogs.msdn.com/rogerla/default.aspx" REL="nofollow"&gt;properties&lt;/A&gt; of the OM new SPWeb objects have been created and it's UP TO US as clients of the OM to dispose of these.&lt;BR/&gt;&lt;BR/&gt;And since the OM is caching all the references and returning the same instance (as you showed with your GetHashCode() sample) we can't even DO this since we might dispose of an object that are later being used in another method.&lt;BR/&gt;&lt;BR/&gt;When we call dispose on the object the ObjectModel doesn't know about this so it's internal member is still set to the same object but NOW THIS OBJECT is disposed !!!&lt;BR/&gt;&lt;BR/&gt;The OM is unfortunately broken.&lt;BR/&gt;&lt;BR/&gt;The only safe way is to NEVER dispose of any objects UNLESS you have explicitly created them yourself.&lt;BR/&gt;&lt;BR/&gt;I'm considering writing a facade ontop of the OM that will reference count everything returned and the client has to dispose of EVERYTHING EVERYTIME and it's up to this layer to now when to actually call dispose.&lt;BR/&gt;&lt;BR/&gt;Thanks&lt;BR/&gt;/Jonas</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/8068833809825688165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/8068833809825688165'/><link rel='alternate' type='text/html' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html?showComment=1213603140000#c8068833809825688165' title=''/><author><name>tojonas</name><uri>http://www.blogger.com/profile/09737649506812317658</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html' ref='tag:blogger.com,1999:blog-4126985520350746834.post-5886455956126422450' source='http://www.blogger.com/feeds/4126985520350746834/posts/default/5886455956126422450' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-46111137'/></entry><entry><id>tag:blogger.com,1999:blog-4126985520350746834.post-2805135819725863148</id><published>2008-06-16T04:19:00.000+01:00</published><updated>2008-06-16T04:19:00.000+01:00</updated><title type='text'>Chris ~&lt;br&gt;&lt;br&gt;I've posted a possible alternative ...</title><content type='html'>Chris ~&lt;BR/&gt;&lt;BR/&gt;I've posted a possible alternative approach &lt;A HREF="http://solutionizing.net/2008/06/15/disposing-lists-spsitespweb-without-parentweb/" REL="nofollow"&gt;here&lt;/A&gt;. Let me know what you think.&lt;BR/&gt;&lt;BR/&gt;Cheers ~&lt;BR/&gt;Keith</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/2805135819725863148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/2805135819725863148'/><link rel='alternate' type='text/html' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html?showComment=1213586340000#c2805135819725863148' title=''/><author><name>solutionizing.net</name><uri>http://solutionizing.net/</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/openid16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html' ref='tag:blogger.com,1999:blog-4126985520350746834.post-5886455956126422450' source='http://www.blogger.com/feeds/4126985520350746834/posts/default/5886455956126422450' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1802091954'/></entry><entry><id>tag:blogger.com,1999:blog-4126985520350746834.post-8490054820817879656</id><published>2008-06-15T22:08:00.000+01:00</published><updated>2008-06-15T22:08:00.000+01:00</updated><title type='text'>A part of the problem is that Microsoft uses the I...</title><content type='html'>A part of the problem is that Microsoft uses the IDisposable interface inconsistently. SPWeb implements it, but SPList doesn't, even though both can contain a reference to a SPRequest object. And that's not the only case where a class that doesn't implement IDisposable can create objects that &lt;I&gt;do&lt;/I&gt; require disposing. While you could use Reflector to find out which methods cause an SPRequest to be instantiated, you shouldn't have to rely on implementation details.&lt;BR/&gt;&lt;BR/&gt;You can avoid this somewhat by instatiating any SPWebs and SPSites that you might need early and dispose those at the very last moment, but that means you'll be holding onto objects longer than necessary and using more resources than you need while your code is running. It still beats the alternative, though.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/8490054820817879656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4126985520350746834/5886455956126422450/comments/default/8490054820817879656'/><link rel='alternate' type='text/html' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html?showComment=1213564080000#c8490054820817879656' title=''/><author><name>Hirvox</name><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img1.blogblog.com/img/blank.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://www.sharepointnutsandbolts.com/2008/06/disposing-sharepoint-objects-what-they.html' ref='tag:blogger.com,1999:blog-4126985520350746834.post-5886455956126422450' source='http://www.blogger.com/feeds/4126985520350746834/posts/default/5886455956126422450' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2039500977'/></entry></feed>
