1

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?

Eric Alexander
  • 43,293
  • 10
  • 53
  • 93
driAn
  • 247
  • 2
  • 7

1 Answers1

4

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

Chris O'Brien - MVP
  • 3,655
  • 18
  • 14