SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Normally it is not required to dispose SPWeb when it is obtained from the current context.

However what happens if I create the context on my own?

        SPContext spContext = SPContext.GetContext(httpContext);
        SPWeb web = spContext.Web;

In this scenario, do I need to dispose the web?

share|improve this question
up vote 4 down vote accepted

No, you don't need to dispose objects hanging off an SPContext obtained this way.

If you look in Reflector, you'll notice SPContext.Current runs this code internally - effectively they do the same thing (which is to deserialize the context information which SharePoint stores in HttpContext.Current.Items).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.