Thursday, November 1, 2012

Detected use of SPRequest for previously closed SPWeb object SharePoint 2010

I got this error message while checking in event viewer in SharePoint server. The full error message is "Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before".

Sometime also you can get error like this "An SPRequest object was not disposed before the end of this thread. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it."
Just to let you know we have some custom web parts, in which we have used SharePoint object model code.

This error ususally comes if you have memory leaks in the code. So we go back and check the code, there we saw some memory leaks cuased by some SPSite and SPWeb objects. Once we corrected them, we did not get the error.

Below are some links you can follow for SharePoint 2010 best practices as well as how to dispose

SharePoint objects and also to detect memory leaks in SharePoint 2010.

- SharePoint 2010 best practices
- Detect Memory leaks in SharePoint 2010
- Dispose SharePoint objects