Pages

Thursday, January 13, 2011

Making use of the SPDisposeCheck utility

Most seasoned SharePoint developers have found out one way or another that you have to be mindful of properly disposing your SharePoint objects. Unfortunately, the rules, guidelines and general practices are often confusing and un-intuitive. Because of this it is common to find SPSite, and SPWeb objects that are not properly disposed. To help combat this issue Microsoft has released a tool called the SPDisposeCheck utility that will analyze your assemblies and report on any improperly disposed Shared Point objects.

The utility can be downloaded here:

http://code.msdn.microsoft.com/SPDisposeCheck

To integrate the utility into your development environment, in Visual Studio go to the "Tools" menu and select the "External Tools" menu item. Select "Add" and configure the tools options as follows:

External Tools Window

The command argument should point to the SPDisposeCheck executable. Pass the project BIN directory as an argument, and set the initial directory to your solution directory. Select the "Use Output window" check-box so that the results from the tool display in the Visual Studio output window.

Output Window

To use the tool, select a project in your solution, and then select the "SPDispose Checker" utility from your tools menu. The results from the tool will display in the output window. If you have any improperly disposed objects, the results in your output window will direct you to where the problems are located in the assembly.

More information about the proper disposal of SharePoint objects the following blog has a great deal of information:

http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx

No comments:

Post a Comment