Undisposed Objects Finder Application

Jun 02
Undisposed Objects Finder Application

The issue

Disposing SharePoint objects is not an easy task especially for new SharePoint developers. Of course, there is a special disposal guideline and a special tool – SPDisposeChecker.

But sometimes that’s not enough:

  1. SPDisposeChecker provides only very limited analyzing options, giving no possibility to track more advanced cases (I’ll show examples in later posts). It’s not supported for SP2013 and VS2012.

  2. Sometimes it’s required to make a code review for an existing project. Especially in a large project :)

Resharper can simplify this process with Find usages command, but it’s still a long task and dependences can still be very complex.

The solution

SharePoint can do this job instead of us – there is a special mechanism for detecting undisposed object before the end of the current thread and logging information to ULS logs – please take a look at this article for more details.

Using this approach it’s possible to activate this mechanism for your SharePoint WFE servers, test application logic and analyze logs for “An SPRequest object was not disposed before the end of this thread”. Using UlsViewer filter can be customized to display only such type of log messages. But for intranet portals or large business applications it’ll take for a while to complete all test cases and analyze logs (with a Microsoft own undisposed objects entries :)).

To overcome these difficulties I’ve create a simple WinForms Application - Undisposed Objects Finder. It goes through ULS logs, parses them and detects  messages for undisposed objects. It allows to:

  1. Scan for undisposed objects log entries and show full stack trace of undisposed SPRequest creation

  2. Exclude logs messages (to filter Microsoft dispose issues)

  3. Include only specific log messages

You can download the application here.

Web Part Error: Activation of solutions with sandboxed code has been disabled. Correlation ID: 2921559e-1047-5000-9318-44914c120b39.