Don’t forget to dispose your SharePoint Objects!


A week ago I pointed to a sample piece of code to retrieve Project Server Settings, today I came across this excellent post from Roger Lamb: SharePoint 2007 and WSS 3.0 Dispose Patterns by Example. If you are using SharePoint objects don’t forget to dispose them!

In the code sample mentioned earlier that is why the “using” directive is used since in C# objects are disposed when it leaves the scope:

using (SPSite sspSite = new SPSite(sspGuid))
{
    if (sspSSL)
        _sspURL = string.Format("https://{0}:56738/{1}", sspSite.HostName, sspName);
    else
        _sspURL = string.Format("http://{0}:56737/{1}", sspSite.HostName, sspName);
}

Two must read MSDN articles on the same subject:

Comments (2)
  1. Martin Winzig says:

    by the way, I don’t t know how to get server name from ApplicationId property so as a shortcut I used name os Shared service Provider administration site, can you ask same smart guys how to get server name from ApplicationId.

Comments are closed.

Skip to main content