2
Vote

SPAlertPipeline class is leaking SPSite and SPWeb instances

description

The SPAlertPipeline class is leaking SPSite and SPWeb instances. When sending the e-mail the following code is used:
 
SPUtility.SendEmail(new SPSite(ahp.siteId).OpenWeb(ahp.webId), ahp.headers, ahp.body);
 
The above line of code creates both a new SPSite and a new SPWeb instance. These have to be disposed of. See Roger Lamb's blog for correct Dispose patterns: http://blogs.msdn.com/rogerla

comments

bobbyangers wrote Feb 13, 2009 at 2:55 PM

Hi,
He is the correction:
            //do the default action first, which is to send out the email
            using(SPSite site = new SPSite(ahp.siteId))
            {
                using(SPWeb web = site.OpenWeb(ahp.webId))
                {
                    SPUtility.SendEmail(web,ahp.headers,ahp.body);
                }
            }

wrote Feb 13, 2013 at 10:49 PM