Avoid Memory Leaks in SharePoint2010 Development
- by ybbest
When you develop SharePoint solution using code, you need to Dispose SPWeb appropriately to avoid memory Leaks. The general guideline for this are:
Dispose
Not to dispose
OpenWebEnumerating Webs or AllWebs
ParentWebRootWeb
SPWeb from SPContext
There are more rules than the one list above and as a smart SharePoint developer, you do not have to memories all the rules .There is a tool called SharePoint Dispose Checker which can help you to find potential memory leak.
To use SPDisposeChecker in you solution, you need to download the tool from MSDN Code Gallery and install it in your development machine as follow.
1. Run the installer with elevated privilege.
2. Accept the agreement and click next.
3. Select those two options and click next.
4. Select Everyone and click Next.
5. Go to Toolsà SharePoint Dispose Check to Configure the SPDisposeCheck.
6. You can change the Treat problems as Errors to Warnings.
7. after clicking Save, you are all set to use the tool.Recompile my project , I can get the result below.
References:
SharePoint 2007/2010 “Do Not Dispose Guidance” + SPDisposeCheck