I have these lines of code:
string siteUrl = "http://myTestSite";
using (SPSite siteCollectionParent = new SPSite(strUrl))
{
SPWebApplication webApplication = siteCollectionParent.WebApplication;
SPSiteCollection childCollections = webApp.Sites;
foreach(SPSite siteCollectionChild in childCollections)
{
try
{
System.Console.Writeline(siteCollectionChild.Url);
}
finally
{
//Add here some code
}
}
}
I want to dispose the SPSite object. Which is the best solution to dispose it? Adding siteCollectionChild.Dispose()
, adding childCollections.Dispose()
or siteCollectionParent
is disposed by garbage collection?