Thursday, February 16, 2012

How to integrate Sharepoint dispose checker into Visual Studio 2010

The first thing you have to do is .Install the spdisposechecker into your machine. You can download the the spDisposeChecker here

Follow the steps for the installation 
1. Run the SPDisposeCheck.msi
2.Click Next

3.Select I agree for the licence agreement click Next.


4.Select the Install Visual studio addin -leave this as blank if you wanted to run as command line tool .Even  if you untick this, you can add the addin to the Visual studio, we will discuss that later.
Tick the Excecute spDisposeCheck if you wanted to run the tool soon after the installation

5.Select an Installation path -note the installation location, this will be used if you didn't tick the install visual studio addin in the previous step.
Click Next


6.Click Close to finish the installation


7.Restart Visual studio -You will find the spDisposeCheck under tools. 

If you havent tick the check Install Visual studio addin follow the steps to add the spDisposeCheck tool to visual studio.

1.Go to Tools -> External tools 
2.Click Add
3.Fill the fields according to the bellow image.

Select the spDisposeCheck installation location for the command textbox.


Run the spDisposeChecke tool to check for any memory leaks this will provide the result in to the output window


·         SPDisposeCheckID_170 It is NOT necessary to dispose the SPWeb object returned by SPWeb.ParentWeb. The dispose cleanup is handled automatically by the SharePoint framework.

·         SPDisposeCheckID_140 It is NOT necessary to dispose the SPWeb object returned by SPWeb.RootWeb. The dispose cleanup is handled automatically by the SharePoint framework.

·         SPDisposeCheckID_220 It is NOT necessary to dispose SPContext objects on your code, since they are managed by the SharePoint framework.

·         SPDisposeCheckID_210 It is NOT necessary to dispose SPContext object returned from calling SPControl.GetContextSite and SPControl.GetContextWeb Methods, since they are managed by the SharePoint framework.

Note: This tool may report errors which are not actually memory leaks, otherwise known as false positives.
Further investigation should be done to identify and correct real errors.
It is designed to assist developers in making sure their code adheres to best practices for memory allocation when using SharePoint APIs.
Please see the following for more information:
http://blogs.msdn.com/rogerla/
http://msdn2.microsoft.com/en-us/library/aa973248.aspx
http://msdn2.microsoft.com/en-us/library/bb687949.aspx


2 comments: