torsdag 7 april 2011

Disposing issues...

So many annoying things concerning disposing SPRequest based objects like SPWeb and SPSite. You can assume that objects like these should be disposed by SharePoint when they are given to you in properies in other objects, like SPListItem.Web, but no...

Examples I've found:

When you do a call to get an SPListItem from an SPItemEventProperties (typically in a receiver like properties.ListItem), if it's the first time you call for the list item, the get method opens up a new SPWeb object to get the list item based in the ListId and ListItemId properties and returns the list item. But the SPWeb object is never disposed. You have to manually dispose it from the list item.

When you call SPListItem.Attachments a similar situation occurs. the SPWeb object in the SPListItem.Web propery gets re-initialized and then you have to dispose it manually.

Pretty annoying ey?

1 kommentar:

  1. Det här inlägget har tagits bort av bloggadministratören.

    SvaraRadera