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?

1 Answer 1


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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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