1
Vote

Non disoposal of SPSite and SPWeb

description

This method in WarmUpJobDefinition.cs does not dispose sites and webs
void AwakeWebApplication(SPWebService webService, Guid webApplicationId)
    {
        // Creating thread for async work
        Thread webApplicationThread = new Thread(delegate(object param)
        {
            SPSiteCollection siteCollection = webService.WebApplications[(Guid)param].Sites;
 
            // Browsing all site collection of the WebApplication
            foreach (SPSite site in siteCollection)
            {
                SPWebCollection webs = site.AllWebs;
 
                // Browsing each web of the site
                foreach (SPWeb web in webs)
                    AwakeURL(web.Url);
            }
        });
 
        // Start the thread
        webApplicationThread.Start(webApplicationId);
    }

comments

enterpriseguru wrote Oct 26, 2012 at 4:38 PM

This is fixed with:

foreach (SPWeb web in webs)
                {
                    try
                    {
                        AwakeURL(web.Url);
                    }
                    // added dispose method for SPWeb object  10-26-12
                    finally
                    {
                        if (site != null)
                            site.Dispose();
                    }
                }

wrote Feb 14, 2013 at 2:51 AM