I ran the SPDisposeCheck tool on my SharePoint assemblies but it reported three errors on a SiteDefinitionAssembly which also has the site provisioning handler. As far as I understand it this code is generated by the project template itself and we are not supposed to change it. The error I get is
ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewInZone(Microsoft.S
harePoint.SPWeb,System.String)
Statement: local6 := local5.{Microsoft.SharePoint.SPFile}GetLimitedWebPartManage
r(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------
ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewOutZone(Microsoft.
SharePoint.SPWeb,System.String)
Statement: local12 := local5.{Microsoft.SharePoint.SPFile}GetLimitedWebPartManag
er(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------
ID: SPDisposeCheckID_160
Module: SynergyOnline.NFER.ProjectSiteDefinition.dll
Method: ProjectSiteDefinition.SiteProvisioning.RestoreDataViewOutZone(Microsoft.
SharePoint.SPWeb,System.String)
Statement: local14 := local11.{Microsoft.SharePoint.SPFile}GetLimitedWebPartMana
ger(1)
Notes: Dispose/Close was not called on SPLimitedWebPartManager.Web
More Information: http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-20
07-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
----------------------------------------------------------
Here is the code that is gerenrated
private void RestoreDataViewInZone(SPWeb web, string filePath)
{
if (!File.Exists(filePath) || web == null)
{
return;
}
XmlDocument doc = new XmlDocument();
try
{
doc.Load(filePath);
}
catch (XmlException)
{
return;
}
XmlNodeList xFixupFiles = doc.DocumentElement.SelectNodes("FixupFiles/FixupFile[@DataViewInZone=\"TRUE\"]");
foreach (XmlNode xFixupFile in xFixupFiles)
{
XmlAttribute xRelativePath = xFixupFile.Attributes["RelativePath"];
if (xRelativePath == null)
{
continue;
}
string relativePath = xRelativePath.Value;
SPFile file = web.GetFile(relativePath);
if (file == null)
{
continue;
}
SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
SPLimitedWebPartCollection pageWebParts = manager.WebParts;
if (pageWebParts == null)
{
continue;
}
foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in pageWebParts)
{
开发者_运维问答 DataFormWebPart dataForm = webPart as DataFormWebPart;
if (dataForm == null)
{
continue;
}
this.SubstituteGuidInZone(web, manager, dataForm, filePath);
}
}
}
I do know that the SPWeb object is not disposed in the function but I am not sure if it should be disposed or not.
Do I need to worry about this error?
Thanks
Finally figured it out
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_160
GetLimitedWebPartManager method returns a SPWeb object which should be disposed.
精彩评论