Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
1  
Maybe it's coming from somewhere else. This error msg says that you can get the stack trace to appear in your log by creating a registry key at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings. Then create a new DWORD named SPRequestStackTrace with the value 1 under this key –  Laurie Jul 6 '11 at 16:10
1  
I don't see anything wrong with that. Properties.Web doesn't need disposed. I also wonder if it's coming from somewhere else. –  Andy Burns Jul 6 '11 at 17:31
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.