SPC110201: Dispose created SPSite objects

When you create a SPSite object with a new operator, the creating application must dispose of it.

TypeName: DisposeCreatedSPSiteObject
CheckId: SPC110201
Severity: CriticalWarning
Type: AssemblyFileReference
Resolution

Call Dispose on created SPSite object or wrap instruction into using statement. See sample from MSDN:

Bad Coding Practice

CreatingSPSiteWithLeak()
{
  SPSite siteCollection = new SPSite("http://moss");
  // ...
  // SPSite object siteCollection is leaked.
}

Good Coding Practice
void CreatingSPSiteWithAutomaticDisposeNoLeak()
{
  using (SPSite siteCollection = new SPSite("http://moss"))
  {
  } // SPSite object siteCollection.Dispose() is called automatically.
}

Remarks

Rule relates to SPDisposeCheckId 'SPDisposeCheckID_110'. To ignore this rule add the attribute '[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_110, "Caller will dispose")]' to your method.

Links

comments powered by Disqus