Welcome to MSDN Blogs Sign in | Join | Help

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:

Published Friday, April 11, 2008 11:55 PM by chrisfie

Comments

Sunday, April 13, 2008 4:40 PM by Martin Winzig

# re: Don’t forget to dispose your SharePoint Objects!

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.

# Links (4/13/2008) « Steve Pietrek’s SharePoint Stuff

Anonymous comments are disabled
 
Page view tracker