سؤال

I have an ItemUpdated event receiver running on a library. Some pretty basic logic. Here's the gist of what I'm doing:

SPWeb web = properties.Web;

SPContentTypeId ParentCT_Id = web.AvailableContentTypes["Some Content Type"].Id;

if (ParentCT_Id != null)
{
    if (properties.ListItem.ContentTypeId.IsChildOf(ParentCT_Id))
    {
        if (properties.ListItem[RECORD_END_DATE] != null)
        {
            SPListItem item = properties.ListItem;

            item.File.CheckOut();

            DateTime endDate = (DateTime)item[RECORD_END_DATE];
            item[RECORD_YEAR_END_DATE] = string.Format("12/31/{0}", endDate.Year.ToString());
            item.UpdateOverwriteVersion();

            item.File.CheckIn(RECORD_YEAR_END_DATE + " has been updated");
        }
    }
}

I'm wondering if I need to be disposing my web object here that I created. I get 6 entries in the ULS log:

An SPRequest object was not disposed before the end of this thread. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. This object will now be disposed.

How should SPWeb objects be disposed in an Event Receiver, if at all? I've even tried putting web.Dispose() at the end, but the entries still show up.

Edit 1

I mentioned that there are 6 entries in the logs, and I believe that corresponds to the number of break points I hit. Not all 6 of these would be making it to the code block above due to some logic. They never instantiate an SPWeb object.

هل كانت مفيدة؟

المحلول

Make sure, you disable the event fireing in your event receiver. Otherwise the event will fire each time you call item.UpdateOverwriteVersion. The memory leak could occur when SharePoint stops this recursion.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top