Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4074650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:11:52+00:00 2026-05-20T17:11:52+00:00

If you start SharePoint and learn about disposing SPSite and SPWeb, almost everybody suggests

  • 0

If you start SharePoint and learn about disposing SPSite and SPWeb, almost everybody suggests to use the “using”-construct if you work with new instances of SPSite and SPWeb.

using (SPSite s = new SPSite("http://yourserver")
{
    using (SPWeb web = s.OpenWeb("http://yourweb")
    {
         // do fancy stuff here
    }
}

I did that too. However, if you look into the SPSite.Dispose() method, you’ll notice that SPSite keeps a reference of its SPWebs created by SPSite.OpenWeb(). On SPSite.Dispose(), all SPWebs tied to this SPSite are diposed. I think (but Im not sure) that virtually all methods which are creating a new SPWeb are adding this SPWeb to the internal collection ‘m_openedWebs’.

This being said, I wonder why you would ever dispose a SPWeb object? Are there any real-world scenarios were you should dispose SPWeb objects?

UPDATE

I just realized, that I spared a little detail which might be important. The SPSite object does not call Dispose() on its child SPWebs, but it is calling Close(). In the current implementation of SharePoint, this is the same as Dispose(), becasue SPWeb.Dispose() just contains:

public void Dispose()
{
    this.Close();
}

So one reason for disposing SPWeb objects might be to be compatible to future SharePoint implementations where SPWeb.Dispose() does not only call SPWeb.Close(). I still find it akward to “double-dispose” my SPWebs only for that reason.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:11:53+00:00Added an answer on May 20, 2026 at 5:11 pm

    You’re right, disposing the SPSite will close the associated SPWeb objects.

    The main scenario where you want to close SPWeb’s right away is when you do something like:

    foreach (SPWeb web in site.AllWebs) 
    { 
         // do something with the web object 
        web.dispose();        // <-- this is mandatory!
    }
    

    For normal opening and closing of one SPSite/SPWeb this doesn’t matter but I would argue it is still good practice (especially for new SharePoint developers).

    If you haven’t already, I would highly recommend reading Stefan Goßner’s post: http://blogs.technet.com/b/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to start off by saying I'm very new to Sharepoint, so I'm
I am new to SharePoint but I learn quick. I want to trigger a
I'm just start using Sharepoint 2010 so this question is difficult for me. The
My Sharepoint 2007 web part executes code to start a K2 workflow process. The
Start a new Silverlight application... and in the code behind (in the Loaded event),
I start to write a client - server application using .net (C#) for both
I have a sharepoint list and user will click 'start now' link in that
I'm using Sharepoint's Copy.asmx webservice to upload legacy files and their metadata. The target
My application is a Silverlight Image viewer that displays images from Sharepoint using the
How can we get a list of start addresses added in a Sharepoint content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.