Wednesday 14 September 2011

SPDisposeCheck in Visual Studio 2010 for Sharepoint 2010

SPDisposeCheck is a tool that helps developers and administrators check custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices. This tool may not show all memory leaks in your code and may produce false positives which need further review by subject matter experts.

In order to use it easily, instead of going to the command prompt approach I will show how to integrate it in your Visual Studio menu.

First of all download the appliocation and install it if you don’t have it: Click Here

1- Go to Visual Studio->Tools->External Tools…

image

2- Click in Add. In Title type netsourcecode_SPDisposeCheck, in Command, type: C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe

3- In Arguments type: $(TargetPath), and tick the “Use Output window” option.

image

4- This is what you will get in your menu:

image

5- To test it, I have decided to add this line in one of the methods of the workflow:

private string GetInitiationData()
{
  SPSite mysite = new SPSite("http://IamACrappyMemoryLeak");
  // TODO: Return a string that contains the initiation data that will be passed to the workflow. Typically, this is in XML format.
  return TextBox1.Text;
}


6- Now go to your netsourcode_SPDisposeCheck tools, click on there, and you should get this message. Notice that complains in the line 30,  that is exactly where the line SPSite mysite = new SPSite(http://IamACrappyMemoryLeak) is:

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
----------------------------------------------------------
ID: SPDisposeCheckID_110
Module: netsourcecodeWithApprovalForm.dll
Method: netsourcecodeWithApprovalForm.Workflow1.WorkflowInitiationForm1.GetInitiationData
Statement: mysite := new Microsoft.SharePoint.SPSite("http://myspfarm")
Source: c:\temp\netsourcecodeWithApprovalForm\netsourcecodeWithApprovalForm\Workflow1\WorkflowInitiationForm1.aspx.cs
Line: 30
Notes: 	 Disposable type not disposed: Microsoft.SharePoint.SPSite
	 ***This may be a false positive depending on how the type was created or if it is disposed outside the current scope
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_110
----------------------------------------------------------
Total Found: 1
----------------------------------------------------------
Modules Checked: 1
----------------------------------------------------------
netsourcecodeWithApprovalForm.dll
----------------------------------------------------------
Modules Ignored: 0
----------------------------------------------------------
----------------------------------------------------------
Methods Ignored: 0
----------------------------------------------------------

Enjoy!

6 comments:

Anonymous said...

Your little dick self works so well: it puts Apple, Google and YouTube functionality.
I was molested again at 13 and 14-years-old. Be that as she
shoots her reality show stars are part of it.
The first thing I'll never offend again'. Check my feedback and you will never walk upright.


Also visit my blog: telefonsex

Anonymous said...

After I initially left a comment I seem to have clicked the -Notify me
when new comments are added- checkbox and from now on whenever a
comment is added I get four emails with the same comment. There
has to be a means you are able to remove me from that service?
Cheers!

Also visit my web blog On front Page

Anonymous said...

I think this is among the most important info for me.
And i'm glad reading your article. But want to remark on few general things, The website style is wonderful, the articles is really excellent : D. Good job, cheers

My weblog; women health forum

chenmeinv0 said...

nike outlet
canada goose outlet
coach handbags
adidas yeezy boost 350
ugg boots
fitflops sale
gucci outlet online
kate spade outlet
louboutin outlet
uggs outlet
2016.12.17xukaimin

yanmaneee said...

air jordan
yeezy boost 350
kyrie irving shoes
yeezy boost
kyrie 5
supreme
kobe basketball shoes
cheap jordans
supreme hoodie
nike off white

Unknown said...

this contentimp source useful referencethis content navigate to this websitetry here