cancel
Showing results for 
Search instead for 
Did you mean: 

ReportDocument.PrintToPrinter function Causes memory leak and Does not release temporary files.

Former Member
0 Kudos

Hi All,

    I have piece of code where I call the PrintToPrinter function to print the contents of the report to directly to printer. Here it prints the contents to the printer, But does not release the memory or temp files created while printing. It happens every time continuously. In fact I am even closing the report using the .Close and .Dispose functions. Still it is causing memory leak and leaves the temp files in the temp folder.

Here is the code that causes the problem.

public void PrintOut(int iCopies, bool bCollated, int iStart, int iStop)

        {

            rptDocument.PrintOptions.DissociatePageSizeAndPrinterPaperSize = false;

            rptDocument.PrintToPrinter(iCopies, bCollated, iStart, iStop);

        }

public void CloseReport()

        {

  frmPrintPreview.Close();

  frmPrintPreview.Dispose();

  rptDocument.Close();

  rptDocument.Dispose();

        }

Any help from any body would be greatly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

What version of .NET?

What version of CR (please be precise - include Service Pack level)?

What utility are you using to determine there is a memory leak? What is leaking - handles, etc.?

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

Hi Ludek,

Thanks for your reply. And here are the details.

.NET version : Crystal Report for .NET Framework 4.0

Crystal Report version : Crystal report for Visual Studio 2010 (SP8)

I am not using any utility, I could see the memory consumption in the Task Manager. Also I could see it is not releasing the temporary files from the TEMP folder. The memory gets cleared only when I close the application window.

I hope this provides some more insight in to my problem.

And Thanks in Advance.

former_member183750
Active Contributor
0 Kudos

Hi Gallen

First, let's get you to SP 10:

Next, see if doing the code as this will help:

public void PrintOut(int iCopies, bool bCollated, int iStart, int iStop)

        {

            rptDocument.PrintOptions.DissociatePageSizeAndPrinterPaperSize = false;

            rptDocument.PrintToPrinter(iCopies, bCollated, iStart, iStop);

           rptDocument.Close();

           rptDocument.Dispose();

        }

- Ludek

0 Kudos

Are all of the temp file being deleted when you close the application?

Also, iterate through about 100 report objects and see if the memory stabolizes, doing one or 2 doe snot give the OS time to actually clean up.

If you let the app and your PC sit idle for an hour or more does the memory get released?

Try adding GC.COllect also, this forces Windows to release everything marked as free sooner then later.

Don

Former Member
0 Kudos

Ludek, Thanks again.

I tried the above code but still, it is not releasing the temp files, or memory while directly printing to the printer.

We understood that SAP API's are clearing the temp files and memory once the Print Job or Print to Preview is done. But in our case after the Print operation we have noticed the temporary files and memory is not cleared. But this is not the case when Print to Preview is executed using CrystalReportViewer class, here both temp files and memory is cleared.

It would be appreciated if you could suggest any SAP Crystal report API to explicitly to clear the print related temp files in temp folder?


Thanks.

former_member183750
Active Contributor
0 Kudos

There is no API that would explicitly delete the temp files.

The .Close and .Dispose APIs clean up the temp folder irrespective of the report being viewed, printed or exported...

Do the temp files get cleared after the app is closed? E.g.; any feedback on Don's suggestions?

- Ludek

0 Kudos

Hi Gallen,

Check your AV software, it's likely blocking CR from deleting the temp files. As ludek also said, all temp files are under the control of crpe32.dll and it does clean up it's temp files. So likely some third party software or permissions is blocking CR from cleaning up those files. Check your AV software logs to see if mentions anything.

Also, just to confirm what is an example of the file names you are seeing left behind? Just to confirm they do belong to CR.

Don

Former Member
0 Kudos

Ludek Thanks a lot for your replies. Actually figured that out and solved the problem. The problem was some other line before dispose function was causing exception and it prevented the dispose function from being executed.

Thanks again

Former Member
0 Kudos

Don thanks to you too. Figured out the problem.

Answers (0)