Pages

Jul 28, 2010

Microsoft.Office.Server.UserProfiles

UserProfiles.PersonalSite requires a Dispose() call before leaving scope if you use the property in your code. For addition code optimization information please see my blog posthere.

void PersonalSiteLeak() {     // open a site collection     using (SPSite siteCollection = new SPSite("http://moss"))     {         UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(siteCollection));         UserProfile profile = profileManager.GetUserProfile("domain\\username");         SPSite personalSite = profile.PersonalSite;    // will leak     } } 
void PersonalSiteNoLeak() {     // open a site collection     using (SPSite siteCollection = new SPSite("http://moss"))     {         UserProfileManager profileManager = new UserProfileManager(ServerContext.GetContext(siteCollection));         UserProfile profile = profileManager.GetUserProfile("domain\\username");         using (SPSite personalSite = profile.PersonalSite)         {             // ...         }     } }


No comments: