Home > Development, Trouble Shooting > SPDisposeCheck

SPDisposeCheck

Every SharePoint Developer should have SPDisposeCheck Tool in there arsnel! This tool, developed by the guys on the SharePoint Team will intergoate your compiled .dll’s to ensure that you are correctly disposing of SharePoint objects, primarily SPSite and SPWeb. Why do we need to dispose of SharePoint object, well from the horses mouth as such :

“Several of the Windows SharePoint Services objects, primarily the SPSite class and SPWeb class objects, are created as managed objects. However, these objects use unmanaged code and memory to perform the majority of their work. The managed part of the object is much smaller than the unmanaged part. Because the smaller managed part does not put memory pressure on the garbage collector, the garbage collector does not release the object from memory in a timely manner. The object’s use of a large amount of unmanaged memory can cause some of the unusual behaviors described earlier. Calling applications that work with IDisposable objects in Windows SharePoint Services must dispose of the objects when the applications finish using them. You should not rely on the garbage collector to release them from memory automatically.”

Roger Lamb has an excellent blog article - SharePoint 2007 and WSS 3.0 Dispose Patterns by Example

Add SPDisposeCheck to Visual Studio

Visual Studio IDE allows you to add External Tools such as SPDisposeCheck. The follow steps explain how:

1. In Visual Studio select Tools | External Tools

2. Add the following settings:

Title:  SPDisposeCheck
Command: C:\Program Files\Microsoft\SharePoint Dispose Check\SPDisposeCheck.exe
Arguements: $(TargetName)$(TargetExt)
Initial Directory: $(TargetDir)
Use Output Window: Checked

SP Dispose Check External Tools

SP Dispose Check External Tools

Reference

Introduction to Using Disposable Windows SharePoint Services Objects

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