Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.