ListItem.Web and ListItem.Web.Site - Dispose or not?

ListItem.Web and ListItem.Web.Site - Dispose or not?

Post by TWlndWVsIE » Wed, 17 Sep 2008 03:00:02


Hello,

I have an event handler that makes access to the following object:

SPWorkflowManager manager = listItem.Web.Site.WorkflowManager;

Do the SPSite and SPWeb objects referenced need to be explicitly disposed? I
read the post by Roger Lamb at
http://www.yqcomputer.com/
and the Microsoft page at
http://www.yqcomputer.com/
articles refer this situation.

Thanks,
Miguel
 
 
 

ListItem.Web and ListItem.Web.Site - Dispose or not?

Post by the_nextma » Thu, 18 Sep 2008 22:37:51

On Sep 15, 2:00m, Miguel Isidoro


I don't know, but if you're not sure why don't you do this:

using(SPWeb myWeb = listItem.Web)
using(SPSite mySite = myWeb.Site)
{
SPWorkflowManager manager = mySite.WorkflowManager;
//code that users spworkflowmanager
}

 
 
 

ListItem.Web and ListItem.Web.Site - Dispose or not?

Post by TWlndWVsIE » Thu, 18 Sep 2008 23:15:01

Hello,

Your suggestion would work, if the objects need to be explicitly disposed.
If they don't, my code should be used instead. In the meantime, I made some
tests, and dispite I am not 100% sure, I believe they don't need to be
explicitly disposed, so my code would work. I would like to know these for
sure. If you or someone, could confirm this, I would be appreciated.

Thanks,
Miguel