My understanding is that ONLY the SPContext calls should not be disposed.

I'd guess there are plenty of leaks when getting a web directly though
(much like the leaks in GetSingle for the ldap/AD code).

On Wed, Mar 26, 2008 at 4:59 PM, Lee Marriage
<[EMAIL PROTECTED]> wrote:
>
>
>
>
> Thanks Sezai, I'll try and get a test lab setup to answer this once and for
> all...
>
>
>
>
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
> Sezai KOMUR
>  Sent: Wednesday, 26 March 2008 4:43 PM
>
>
>  To: [email protected]
>  Subject: [OzMOSS] RE: Object Disposal in Feature Receivers
>
>
>
>
>
> Yes it's confusing for Feature Receivers.
>
>
>
> Read the first comment here, someone states its appropriate to use dispose
> on SPWeb in a SPFeatureReceiver, because "you're getting a new instance of
> SPWeb"
>
> http://weblogs.asp.net/bsimser/archive/2008/02/25/getting-sites-and-webs-during-feature-activation-in-sharepoint.aspx
>
>
>
> Although, the example on that page does not use dispose. Still I am not 100%
> sure or convinced you have to dispose in case of using
> properties.Feature.Parent in a Feature Receiver.
>
>
>
> To determine for sure try setting up a test involving deployment of many
> Feature Receivers that don't dispose the SPWeb, fire all the receivers
> continuously and then monitor the memory usage on your server. It might take
> a while to setup a test like that, and you would want to run it on a fresh
> farm in case other custom object model code is causing memory leaks.
>
>
> Sezai Kömür
>  Senior Developer  - BEng, BSc - Microsoft Certified Technology Specialist
> -  http://www.moss2007.com.au/
>
>
>
>
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
> Lee Marriage
>  Sent: Wednesday, 26 March 2008 2:16 PM
>  To: [email protected]
>  Subject: [OzMOSS] RE: Object Disposal in Feature Receivers
>
>
>
> Thanks guys, I understand the basic concepts that you outline of when to
> dispose and when not to dispose but I guess what I was after was more detail
> to understand this specific 'FeatureReceiver' scenario; so to recap.
>
>
>
> Good
>
> SPWeb web = siteCollection.OpenWeb();
>
> //Do Some stuff with web
>
> Web.Dispose();
>
> * or by wrapping the code with the using() { } statement.
>
>
>
> Not Good
>
> SPWeb web = SPContext.Current.Web;
>
> Web.Dispose();
>
>
>
> This article
> http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx
> states that the objects returned by methods 'GetContextSite' and
> 'GetContextWeb' as well as the properties 'SPContext.Current.Site',
> 'SPContext.Site', 'SPContext.Current.Web' & 'SPContext.Web' do not require
> explicit disposal. All good I won't go disposing those. However, the article
> also shows another example where a call to the 'ParentWeb' property of a web
> returns an SPWeb object that does require disposing.
>
>
>
> So going back to the question; does the object returned by the call to the
> SPFeature's 'Parent' property require disposal? In the following sample
>
>
>
> SPWeb myweb = (SPWeb)properties.Feature.Parent;
>
>
>
> An SPWeb object is created (myweb) by calling the SPFeature.Parent property
> and casting it as SPWeb. So as we are creating the SPWeb object (myweb) best
> practices states that we should close this object using myweb.Dispose()
> method.
>
>
>
> But if my understanding of Michael and Sezai's responses is correct then I
> shouldn't myweb.Dispose() because the SPFeature is a shared resource (like
> SPContext or SPControl) so SharePoint will take care of the disposal? Is
> this correct or am I confusing myself further J
>
>
>
>
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
> Sezai KOMUR
>  Sent: Wednesday, 26 March 2008 1:22 PM
>  To: [email protected]
>  Subject: [OzMOSS] RE: Object Disposal in Feature Receivers
>
>
>
> Michael is right, at times you don't need to dispose of SharePoint objects
> is if you are writing code that will run in-context of a SharePoint Site, so
> a web part or control added to a sharepoint site which may programmatically
> access SPWeb as a shared resource you don't need to dispose the object.
>
>
>
> On the other hand if you are creating a SharePoint Context programmatically,
> say in a console app or a winforms app then your MUST remember to dispose of
> objects correctly as SharePoint won't do it for you.
>
>
>
> http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spweb.dispose.aspx
>
> If you create an SPWeb object, you can use the Dispose method to close the
> object. However, if you have a reference to a shared resource, such as when
> the object is provided by the SPControl.GetContextWeb method, do not use the
> Dispose method to close the object, but instead allow Windows SharePoint
> Services or your portal application to manage the object.
>
>
>
> A page with links to other related resources discussing memory issues caused
> by custom SharePoint development -
> http://www.21apps.com/2008/02/sharepoint-ate-all-my-memory-dealing.html
>
>
>
>
> Sezai Kömür
>  Senior Developer  - BEng, BSc - Microsoft Certified Technology Specialist
> -  http://www.moss2007.com.au/
>
>
>
>
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
> Michael Nemtsev
>  Sent: Wednesday, 26 March 2008 10:10 AM
>  To: [email protected]
>  Subject: [OzMOSS] RE: Object Disposal in Feature Receivers
>
>
>
> AFAIK it's not the case where u should dispose your resources. There are a
> few cases to dispose SPWeb, but feature not the case
>
>
>
>
> Michael Nemtsev
>  Readify |  Senior Developer
>  Microsoft MVP [.NET/C#]
>
> Tel: +61 424 184 978 | Email: [EMAIL PROTECTED]
>
>
>
>
>
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
> Lee Marriage
>  Sent: Wednesday, March 26, 2008 11:26 AM
>  To: [email protected]
>  Subject: [OzMOSS] Object Disposal in Feature Receivers
>
>
>
> A question on object disposal which has sparked a little debate. When
> calling the FeatureActivated method, the object to the parent site can be
> found at 'properties.Feature.Parent'.  Best practices for using objects
> which implement the IDisposable interface say to call the Dispose() method
> when finished using the object.
>
>
>
> For example:
>
> using (SPWeb web = (SPWeb)properties.Feature.Parent)
>
> {
>
> //.... Do something here
>
> }
>
> or this way:
>
> SPWeb web = (SPWeb)properties.Feature.Parent
>
> web.Dispose();
>
>
>
> However having read this article
> http://msdn2.microsoft.com/en-us/library/aa973248.aspx and seen many
> examples on the www where the 'properties.Feature.Parent' isn't explicitly
> disposed a debate has been sparked as to whether or not getting the web (or
> site) using 'properties.Feature.Parent' requires disposal in the
> aforementioned manner?
>
>
>
> So what says you; to dispose or not to dispose?
>
>
>
> Cheers,
>
> Lee Marriage
>
> -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
>
> -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
>
> -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
>
> -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
>
> -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
>
>  -------------------------------------------------------------------
> OzMOSS.com - to unsubscribe from this list, send a message back to the list
> with 'unsubscribe' as the subject.
>  Powered by mailenable.com
;3I'(��.�˛���m���ka��b���֦z����rKh����p��n�˛���m欶����r�����u��j)^���y�&

Reply via email to