Hello I am having trouble with disposing the SPweb and SpSite. The web part is loading superslow because the objects are not dipsosed properly. I am pretty sure its SPWEB and Spsite causing it and suggestions. I am not sure how to dispose it properly.
public Dictionary<string, List<string>> newData()
{
string url = HttpContext.Current.Request.Url.Host;
SPSite siteCollectionOuter = new SPSite(url))
SPWeb sPWeb = sPSite.OpenWeb();
SPListCollection sPListCollection = sPWeb.Lists;
Dictionary<string, List<string>> newData = new Dictionary<string, List<string>>();
List<string> subject = new List<string>();
if (sPListCollection.Count > 0)
{
foreach (SPList list in sPListCollection)
{
if (list.BaseTemplate == SPListTemplateType.DiscussionBoard)
{
SPListItemCollection ListRows = list.Items;
SPListItemCollection oldTopics = list.Folders;
foreach (SPListItem topic in oldTopics)
{
if (topic["Subject"] != null)
{
subject.Add(topic["Subject"];
}
else
{
subject.Add("");
}
}
}
}
newData.Add("Subject", subject);
}
return newData;
}