IIS worker process memory keeps increasing with each new devexpress report beeing served

33 Views Asked by At

This is using Dotnet Framework 3.5. The reports contains many high resolution images. I need to know how proper disposal should be done please.

 // ReportViewer.aspx.cs
 protected void Page_Load(object sender, EventArgs e)
 {

     XtraReport report = new XtraReport();
     report.LoadLayout(reportsDirectory + "\\" + Request.Params["rptnme"]);
     //For backward compatibility
     SqlDataSource.DisableCustomQueryValidation = true;
     SqlDataSource.AllowCustomSqlQueries = true;

     //Allow all scripts to be run via devexpress for backward compatibility
     ScriptPermissionManager.GlobalInstance = new ScriptPermissionManager(ExecutionMode.Unrestricted);

     if (report.DataSource is SqlDataSource)
     {
         ParseParams(report);
     }

     if (report.DataSource != null)
     { 
         report.DataSourceDemanded += report_DataSourceDemanded;
         ((SqlDataSource)report.DataSource).ConfigureDataConnection += new ConfigureDataConnectionEventHandler(devReports_Default_ConfigureDataConnection);
     }

     SubReports(report);

     if (Request.Params.Count > 0)
     {
         if (Request.Params["DisplayName"] != null)
         {
             report.DisplayName = Request.Params["DisplayName"];
         }
     }

     if (Request.Params["exptyp"] == "pdf" || Request.Params["exptyp"] == "ALL")
     {
         // Specify export options.
         PdfExportOptions pdfExportOptions = new PdfExportOptions()
         {
             PdfACompatibility = PdfACompatibility.PdfA1b
         };
       
     }

     DocViewer1.OpenReport(report);
     
 }
// ReportViewer.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server">
    <div>
        <dx:ASPxWebDocumentViewer ID="DocViewer1" runat="server"           
          ToolbarMode="Ribbon" DocumentViewerInternal="">
        </dx:ASPxWebDocumentViewer>
    </div>
</form>
</body>
</html>

This code is part of an ASP.NET Web Forms page that is used to load and display a report using DevExpress's reporting tools. Here's a breakdown of what the Page_Load method does:

  1. It first creates a new XtraReport object, which represents a report.
  2. It then loads the layout of the report from a file. The file path is constructed by concatenating the reportsDirectory (which is read from the application's configuration) and the report name, which is passed as a parameter in the request.
  3. It disables custom query validation and allows custom SQL queries for the SqlDataSource. This is done for backward compatibility.
  4. It sets the ScriptPermissionManager.GlobalInstance to a new ScriptPermissionManager with ExecutionMode.Unrestricted, which allows all scripts to be run via DevExpress for backward compatibility.
  5. If the report's data source is a SqlDataSource, it calls the ParseParams method to parse the parameters for the report's queries.
  6. If the report has a data source, it subscribes to the DataSourceDemanded event and the ConfigureDataConnection event of the SqlDataSource. The DataSourceDemanded event is raised when the report's data source is demanded, and the ConfigureDataConnection event is raised when the data connection of the SqlDataSource needs to be configured.
  7. It calls the SubReports method to handle any subreports in the report.
  8. If there are parameters in the request, it sets the display name of the report to the value of the "DisplayName" parameter.
  9. If the "exptyp" parameter in the request is "pdf" or "ALL", it creates a new PdfExportOptions object and sets its PdfACompatibility property to PdfACompatibility.PdfA1b. This is used to specify the options for exporting the report to PDF. However, the actual export to PDF is commented out in this code.
  10. Finally, it opens the report in DocViewer1, which is a ASPxWebDocumentViewer control that displays the report to the user. This method is called every time the page is loaded. It reads the report name from the request parameters, loads the report, configures it, and displays it to the user.
1

There are 1 best solutions below

0
Marius On

We'll automatically dispose all contained images once a report is disposed. However, the situation is much more complex when it comes to ASPxWebDocumentViewer. The life cycle of your web page is much shorter than the life cycle of a previewed report document. As we don't want to recreate the entire document each time you export or navigate between pages, we need to keep it somewhere. Each time you preview a report (e.g., by refreshing the page the browser), you get a new document copy (the previous one is not automatically removed unless you do that explicitly). That's why you see a constant increase in memory usage. This may look like a memory leak, but it's not. Moreover, we're trying to be smart about caching: we have not one, but two storages (in-memory and persistent). The persistent storage is also used to share documents across servers in the Web Farm environment. Check these help topic and let me know if you have any follow-up questions: Document Viewer Lifecycle Document Viewer Cache Management.

Note. If your documents (images) are really large and you wish to have direct control over the report's lifetime, I'd recommend testing our PdfStreamingExporter. This mediator was created specifically for large reports where pages are written as soon as they are ready. While this alternative implies no ASPxWebDocumentViewer, you can still use the browser's built-in PDF viewer to visualize the result.

Regards, Yaroslav DevExpressSupport