Saturday, 31 January 2009

Disposing SharePoint Services Objects Updated (2009) and SharePoint Dispose Checker

Microsoft has finally released an update to the "Best Practices: Using Disposable Windows SharePoint Services Objects" article. If you've never heard about, glanced through, or read this article, it's required reading for every WSS/MOSS developer and worth printing off.

It's terribly important to remember that, even though you're writing code for a managed environment (.NET), you're not always dealing with managed objects; think of your MOSS objects (well, some of them anyway) as unmanaged resources that require special handling just like files and database connections. If you don't dispose of these objects properly, they'll sit in memory until the IIS application pool falls over and your site crashes. It happens and the existence of this article suggests it happens too much! The flip side is disposing of MOSS objects that shouldn't be disposed, which can also have negative consequences.

To coincide with this guidance, the SharePoint Dispose Checker tool (SPDisposeCheck) has also been released on the MSDN Code Gallery. Pointing this tool at your custom MOSS assemblies will tell you where you've gone wrong. The tool won't find every problem and may also report errors which are not actually problems but in general it's a great addition to your toolbox and a perfect compliment to the guidance. The tool can be used with MOSS or WSS assemblies. Note the -xml parameter doesn't work with this release--leave it off the call and pipe the output to a txt file. 

The tool is installed to "C:\Program Files\Microsoft\SharePoint Dispose Check" and running against the sample spits out a list of problems that look something like this:
ID: SPDisposeCheckID_160
Module: SPDisposeExamples.exe
Method: SPDisposeExamples.SPWebLeak.SPLimitedWebPartManagerLeak
Statement: webPartManager := page.{Microsoft.SharePoint.SPFile}GetLimitedWebPartManager(1)
Source: C:\ROGERLA\Demo\SPDisposeExamples\SPWebLeak.cs
Line: 42
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information:
Interpreting the SPDisposeCheck's output isn't difficult but note the tool may output a lot of information before telling you about the problems encountered. Scanning the .dlls resulted in a 10MB text file to report three problems so I'd suggest you start reading the output file from the bottom up or run the tool without the -debug parameter. Also make sure you read the readme file as it's not only quite useful but brief.

Finally, despite being labelled "Best Practice", this guidance has danced around since it was first published in 2006. But don't worry, Roger Lamb keeps and excellent, up-to-date
blog post on how to implement this guidance and any changes that come up. Apparently Roger's blog will be the default location where updates are published prior to incorporation into the doc proper. 

Custom-Built Microsoft Office SharePoint Server 2007 Branded Sites and Webpart Development -

Friday, 16 January 2009

Perth 'Hots Up' while MOSS 2007 Jobs Cool Down

Eighteen months ago a job search on returned many pages of Perth-based jobs for SharePoint/MOSS developers and the whole situation felt out of control (kind of like today's temperature here in the city). MOSS 2007 was new-ish and the Microsoft marketing machine was working overtime. Everyone had to have MOSS and they wanted it now! As a MOSS dev looking to move employers, the streets were seemingly paved with gold--any job offer would be very much on my terms and it would pay well (especially as a contractor).

To satisfy my curiosity (I'm not job hunting at the moment), today I repeated the original search I ran on seek in mid-2007 and the results were, well... few: two listings for 'MOSS 2007' and eight listings for 'SharePoint'--only three of which included the word 'SharePoint' in the title. Maybe it's the time of year and the global economy is definitely out of sorts but I've got to admit this was surprising!

Custom-Built Microsoft Office SharePoint Server 2007 Branded Sites and Webpart Development -

Friday, 2 January 2009

Software KVM

I never knew such a thing existed but Synergy is a software-based client/server application for sharing a mouse and keyboard across two systems and it's free. Note I didn't mention anything about the video side because the video aspect isn't covered by this tool. 

After some minor but clunky configuration to identify the server and tell the server where it sits physically in relation to the clients, this thing is dead easy to use: it's just like moving between windows on your extended Windows desktop except keyboard input is automatically "focused" (eg. no click required) on your moused-into computer, if that makes sense. 

I've got two machines on my desktop at work: my laptop with its desktop extended to a 22" Samsung and my VPC host machine--a grunty box with a single 17" monitor. By putting the lot side-by-side I can now remove one keyboard and mouse from my desktop--a minor win but pretty cool nonetheless. 

Custom-Built Microsoft Office SharePoint Server 2007 Branded Sites and Webpart Development -