Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

Disposing SPSite object in EmailReceived event

$
0
0

Ok so i have already read all of these articles:

Best Practices: Using Disposable Windows SharePoint Services Objects

Disposing Objects

SharePoint 2007 and WSS 3.0 Dispose Patterns by Example

Disposing SPWeb and SPSite objects

SharePoint 2010 - Do not dispose guidance for SharePoint objects

But there's one more thing i would like to know. Should i dispose "site" object referenced below? One of articles above explains that we dont have to dispose *.ParentWeb. The other one states that all objects created using event properties object, shouldnt be disposed. So what should i do in this particular case? Dispose or not? :)

  SPSite site = null;
        public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
        {
            base.EmailReceived(list, emailMessage, receiverData);
            site = list.ParentWeb.Site;
            //some code here
            try
            {
                //some code here
            }
            catch() {}
            finally
            {
               if(site!=null) site.Dispose();
            }
       }
//other methods where im using site object



Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>