Home > SharePoint 2010, SharePoint Tools > Avoid Memory Leaks in SharePoint2010 Development

Avoid Memory Leaks in SharePoint2010 Development

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

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: