我有一个WindowsService,它通过LocalReports (RDLC报告)将XML文件转换为PDF。它工作得很好,而且速度很快,但我正在努力解决类似于那些here的内存泄漏问题。
看来,.Render("PDF")方法是问题出现的地方。VS2015中的分析会话显示了ServerIdentity使用的大量内存。如果我注释掉.Render("PDF"),就不会出现这种情况。
规格
代码
public static byte[] GenerateReport(string name, IEnumerable<ReportDataSource> dataSources)
{
try
{
byte[] pdfBytes;
using (Stream reportStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
{
LocalReport localReport = new LocalReport();
localReport.LoadReportDefinition(reportStream);
foreach (var dataSource in dataSources)
{
localReport.DataSources.Add(dataSource);
}
pdfBytes = localReport.Render("PDF");
//Cleanup!
localReport.DataSources.Clear();
localReport.ReleaseSandboxAppDomain();
localReport.Dispose();
}
return pdfBytes;
}
catch (Exception ex)
{
throw new Exception("Error generating report at " + name, ex);
}
}其他注释
.Render("PDF"),内存就不会超过20 so左右。ServerIdentity或ServerIdentity对象。这就是消耗内存的90%+的地方,但是我没有办法去GC那个内存。发布于 2020-11-26 16:42:07
将应用程序的编译目标更改为x64并调用
report.ReleaseSandboxAppDomain();后渲染法请记住释放报表对象。
https://stackoverflow.com/questions/33376285
复制相似问题