Share via


Use the Close() Method to free up the report

Another way to optimize scalability in a Crystal Reports for Visual Studio project is to use one of the available Close() methods to release the memory that is used by the report.

Two Close() methods are available:

  • ReportDocument.Close() that is used with Crystal Reports.
  • ReportClientDocument.Close() that is used with the RAS SDK.

The ReportDocument.Close() method

When using Crystal Reports for Visual Studio, you can use the ReportDocument.Close() method to release the memory that the Crystal report consumes on the Web server.

How the ReportDocument.Close() method is accessed depends on whether the report is embedded or non-embedded:

  • If the report is embedded, a report wrapper class is generated to represent the report in code. This report wrapper class inherits from ReportDocument, and the Close() method is accessed by inheritance.

  • If the report is not embedded, it is loaded from the file directory into an instance of ReportDocument, and the Close() method is accessed directly from the ReportDocument class.

    Note

    For more information on embedded and non-embedded reports, see Should I Use Embedded or Non-embedded Reports?.

Both the Crystal report and the instance of the ReportDocument each consume memory. When the ReportDocument is freed from memory, the report continues to use memory.

For example, the ReportDocument instance falls out of scope when the Web page finishes loading. When the garbage collection for .NET disposes of the ReportDocument instance, the memory that is used by the ReportDocument instance is released from the Web server.

However, the report itself remains in memory on the Web server. It cannot be removed, because a ReportDocument instance no longer exists to access the report. When those circumstances are repeated in a highly scaled situation, the memory on the Web server fills with reports that are no longer being accessed.

To resolve that problem, call the ReportDocument.Close() method. The report itself is closed on the Web server and the memory is released for further reports.

When to call the ReportDocument.Close() method

The ReportDocument.Close() method should not be called on the page before the report has been displayed because, even if the report has been closed, ReportDocument will reopen the report if it is referenced again. The Close() method should only be called after the display process is complete.

The right time to call the Close() method is during the Page_Unload event.

The ReportClientDocument.Close() method

When using an unmanaged RAS or managed RAS server, reports are stored on the Report Application Server, but they are represented on the Web server by an instance of ReportClientDocument. If the ReportClientDocument instance passes out of scope without calling the ReportClientDocument.Close() method, the Report Application Server keeps the report open in memory, even though the report can no longer be accessed. When those circumstances are repeated in a highly scaled situation, the memory on the Report Application Server fills with reports that are no longer being accessed on the Web server.

To resolve that problem, call the ReportClientDocument.Close() method. The report is closed on the Report Application Server and the memory is released for further reports.

When to call the ReportClientDocument.Close() method

The Close() method should not be called on the page before the report has been displayed, because the report must remain open on the server until the display process has been completed.

For a ReportClientDocument instance, the Close() method immediately closes the report and the report cannot be reopened. Therefore, if the Close() method is called before the report is displayed, the report will be inaccessible and an exception will be thrown.

The right time to call the Close() method is during the Page_Unload event.