In some cases such as:
using (SPSite site = new SPSite(@"http://sitecollection/"))
{
SPWeb web = site.RootWeb;
}
you don't need to dispose of the SPWeb object because it is disposed of automatically by the garbage collector. Same with SPItemEventProperties, e.g.
private static void ItemUpdated(SPItemEventProperties properties)
{
SPWeb web = properties.Web;
}
What are the dangers of disposing of these SPWeb objects when they are already automatically disposed of? It has been so ingrained to always dispose of SPWeb objects that in some of my older code, I have disposed of the SPWeb object returned from site.RootWeb
or properties.web