using() is best practice, and you don't need to call .Dispose() typically with
this method, and one of most common issues of using web.Dispose(); is that
sometimes you dispose of the object prematurely, and have to recreate it again,
and again, and dispose of it again and again...
From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Wed, 26 Mar 2008 11:25:50
+1100Subject: [OzMOSS] Object Disposal in Feature Receivers
A question on object disposal which has sparked a little debate. When calling
the FeatureActivated method, the object to the parent site can be found at
'properties.Feature.Parent'. Best practices for using objects which implement
the IDisposable interface say to call the Dispose() method when finished using
the object.
For example:
using (SPWeb web = (SPWeb)properties.Feature.Parent)
{
//.... Do something here
}
or this way:
SPWeb web = (SPWeb)properties.Feature.Parent
web.Dispose();
However having read this article
http://msdn2.microsoft.com/en-us/library/aa973248.aspx and seen many examples
on the www where the ‘properties.Feature.Parent’ isn’t explicitly disposed a
debate has been sparked as to whether or not getting the web (or site) using
‘properties.Feature.Parent’ requires disposal in the aforementioned manner?
So what says you; to dispose or not to dispose?
Cheers,
Lee Marriage-------------------------------------------------------------------
OzMOSS.com - to unsubscribe from this list, send a message back to the list
with 'unsubscribe' as the subject.Powered by mailenable.com
------------------------------------------------------------------- OzMOSS.com
- to unsubscribe from this list, send a message back to the list with
'unsubscribe' as the subject.
Powered by mailenable.com