I have a function that will will generate a dataset and create an xml file from it. The function is working perfectly. The problem is that I will get an "Out of memory" error after running the report several times. When I test the report I found that the memory usage will increase a lot when it reachs this XmlDocument command. I used the GC but no use, any suggestions?
if (ddlDir.SelectedItem != null && ddlSec.SelectedItem != null)
{
using (DataSet dsClosedKPICalls = GetReportData())
{
dsClosedKPICalls.DataSetName = "ClosedKPICalls";
foreach (DataTable table in dsClosedKPICalls.Tables)
{
table.TableName = "ServiceInfo";
}
XmlContent = dsClosedKPICalls.GetXml();
}
XmlDocument XML_Data = new XmlDocument(); // contains the resultant XML data
XML_Data.LoadXml(XmlContent);
XmlNodeList TablesList = XML_Data.SelectNodes("ClosedKPICalls/ServiceInfo");
for (int i = 0; i < TablesList.Count; i++)
{
XmlDocument innerXML = new XmlDocument();
using (DataSet dsTaskDetails = getSplitupRecords(TablesList.Item(i).SelectSingleNode("ServiceNo").InnerText))
{
dsTaskDetails.DataSetName = "TaskDetails";
foreach (DataTable tbl in dsTaskDetails.Tables)
{
tbl.TableName = "RequestInfo";
}
innerXML.LoadXml(dsTaskDetails.GetXml());
TablesList.Item(i).AppendChild(XML_Data.ImportNode(innerXML.SelectSingleNode("TaskDetails"), true));
innerXML = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}