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:
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.
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.
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:
Scan for undisposed objects log entries and show full stack trace of undisposed SPRequest creation
Exclude logs messages (to filter Microsoft dispose issues)
You can download the application here.