how to ensure proper cleanup of
reports
It is particularly important if your application comes under
load.Reports left open take up resources, which, if left unchecked, can starve
your app of resources, leading to performance degradation, report request
denial, and out of memory problems.And one more thing is it will block the
database resources also.
Destroy
every ReportSource
Every time a ReportClientDocument opens a report rpt file,the
reference count for that report instance is incremented. Every time an unique
ReportSource is retrieved from the ReportClientDocument, the count is
incremented.Every time a ReportClientDocument is closed, the reference
count is decremented. Every time a ReportSource is destroyed, the count is
decremented.If ReportClientDocument or ReportSource is not cleaned up,
then the instance will remain live and taking up resources until timeout garbage
collects the object.
One
important consideration is the following: even if you invoke
ReportClientDocument.close(), that report may still not be
closed.
Here's a simple test:
(1) open a report with a ReportClientDocument.
(2) retrieve a ReportSource using the method ReportClientDocument.getReportSource().
(3) invoke the ReportClientDocument.close() method for that instance.
(4) test the value of ReportClientDocument.isOpen() - you'll see that it's true!.
(5) pass the ReportSource object to the CrystalReportViewer, and invoke CrystalReportViewer.dispose().
(6) now check ReportClientDocument.isOpen() again - you'll see that it's false, i.e., that the instance has been cleaned up.
Another consideration: the only way to dispose the ReportSource is to pass it to a viewer object
(1) open a report with a ReportClientDocument.
(2) retrieve a ReportSource using the method ReportClientDocument.getReportSource().
(3) invoke the ReportClientDocument.close() method for that instance.
(4) test the value of ReportClientDocument.isOpen() - you'll see that it's true!.
(5) pass the ReportSource object to the CrystalReportViewer, and invoke CrystalReportViewer.dispose().
(6) now check ReportClientDocument.isOpen() again - you'll see that it's false, i.e., that the instance has been cleaned up.
Another consideration: the only way to dispose the ReportSource is to pass it to a viewer object
Invoking viewer dispose() will in turn invoke the proper dispose
method for the ReportSource.
we will prove this in one more way
before opening of report in application open the sql editor and run
the below query
SHOW FULL PROCESSLIST
IT DISPLAYS NO OF PROCESS ID'S
after that open the report and again run the above query one more
process id created even after closing of the report process id not
decreasing
that is why with crystal reports code we are facing some memory
problems. So better to use crviewer.dispose() .