PROBLEM:
========
- Consider you've a ASP.NET application that contains Report Viewer control (2005 / 2008) in Local Mode.
- You have an RDLC report file, that loads large amount of data / has lots of expressions. (Both are not recommended in Local mode)
- Everytime you refresh the web page, the Report Viewer stores objects in the session.
- The behaviour of Report Viewer storing objects in the session is by design.
- Each time the report viewer page is refreshed the complete report info object is added to session.
- These objects obviously gets deeply rooted in session and so Garbage collector never collects them untill the complete app unloads itself.
- And that is apparently going to increase the memory pressure in multiple folds, ending up with System.OutOfMemoryException.
RESOLUTION: (Please note: This doesn't guarantee to resolve the exception. The Out of Memory exception can be caused due to different reasons and the below workaround is for one such scenario, which can help to avoid this error to a certain extent.)
===========
== In the page_load event, add this,
if(Session.Count > 0)
{
for (int i = 0; i < Session.Count; i++)
{
if (Session[i].GetType().ToString() == "Microsoft.Reporting.WebForms.ReportHierarchy")
{
Session.RemoveAt(i);
}
}
}
本文介绍了一种在ASP.NET应用中使用本地模式ReportViewer控件时遇到的内存溢出问题及解决方案。当加载大量数据或使用复杂表达式时,ReportViewer会将报告对象存储在会话中,导致内存压力增加,最终可能引发System.OutOfMemoryException异常。文章提供了一个工作区解决方案,通过在页面加载事件中清理特定类型的会话对象来缓解这一问题。
8245

被折叠的 条评论
为什么被折叠?



