locked
Should we dispose SPContext.Current.Web? RRS feed

  • Question

  • after reading the best practices on using disposable window sharepoint services objects

    http://msdn2.microsoft.com/en-us/library/aa973248.aspx


    The article talks about not to dispose objects obtained from SharePoint context objects - Quote:

    SPControl.GetContextSite and SPControl.GetContextWeb Methods

    If the object is obtained from the SharePoint context objects (SPControl.GetContextSite method and SPControl.GetContextWeb method), the calling application should NOT call the Dispose method on the object. Doing so may cause the SharePoint object model to behave unpredictably or fail. This is due to an internal list that is kept in the SPSite and SPWeb objects derived in this way. Internally, the object model enumerates over this list after page completion to dispose of the objects properly.



    However the article doesn't cover SPContext.Current.Web.  My gut feeling is to leave it alone.  But I would like some confirmation please.



    Thanks



    Rushui






    Friday, December 28, 2007 3:35 PM

Answers

  • Thats a good gut feeling. The SPContext.Current.Web uses the SPControl.GetContextWeb method.

    Friday, December 28, 2007 5:20 PM