我有一个函数将生成一个数据集并从中创建一个 xml 文件。该功能运行良好。问题是多次运行报告后会出现“内存不足”错误。当我测试报告时,我发现当它到达这个 XmlDocument 命令时,内存使用量会增加很多。我用了GC但没用,有什么建议吗?
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();
}
}
}