Skip to Content

memory leak with windows service


comparable to description of , I still do have the same problem.

The application runs as a windows service on Windows Server 2012.

I'm using Crystal Report v13.0.13 for .NET (x64 , Framework 4.5.2) with visual studio 2013.

Accourding to the "Fixed issues" at this problem has not been fixed in th newer releases.

The problem exits since we migrated the project from 32-bit to 64-bit and from VS 2008 to VS2013.

It is definitly Crystal R. that does not free the memory correctly.

Which further informations do you need to fix this bug?

Thanks in advance!

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • Best Answer
    Mar 29, 2016 at 03:34 PM

    The thing to remember is that the Crystal and BO SDKs are based on COM objects, which can cause memory leaks if not handled correctly. So, when possible, you should either enclose calls to a report in the SDK with a "using" clause, or explicitly call .dispose() on the report when you're done with it.


    Add comment
    10|10000 characters needed characters exceeded

    • Thank you for your fast response. Unfortunately that's what I am already doing: .Dispose() on the Crystal R.-object and additionally on the DataSet and tables.



      try { [...] crReportDocument = new ReportDocument(); crReportDocument.Load(pathReport); crReportDocument.SetDataSource(dsData); crReportDocument.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape; crReportDocument.SetParameterValue("finalized", false);

      if (myDestination.Equals(DestinationChoice.toDisk)) { crReportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, fileWithPath); } else if (myDestination.Equals(DestinationChoice.toHttpResponse)) { crReportDocument.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, true, filename); } } catch (Exception ex) { throw ex.ToString(); } finally { if (crReportDocument != null) { crReportDocument.Close(); crReportDocument.Dispose(); } tabMaindata.Clear(); tabMaindata.Dispose(); tabSubrpdata.Clear(); tabSubrpdata.Dispose(); dsData.Clear(); //DataSet contains tabMaindata and tabSubrpdata dsData.Dispose(); } }
  • Mar 29, 2016 at 08:56 PM

    How do you know there is a memory leak? E.g.; errors? symptoms? behavior? What tool do you use the track the memory usage?

    How do you know it is CR that is leaking?

    - Ludek

    Senior Support Engineer Product Support, Global Support Center Canada

    Follow me on Twitter

    Got Enhancement ideas? Use the SAP Idea Place

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Don,

      > If you stop the service does it clean up those temp files?

      The service has no remaining temp files. The webproject does not clean up the mentioned temp-files.

      Regarding webproject "B":

      yes, we are using sessions for the website (no cookies).

      Looking at the history of this thread - shall I prepare a VS-project with our *.RPT for debugging that on your own?

      It is no CR-migration-problem (update from CR-vXY), because it the same with a newly created RPT (with VS 2013).

      UPDATE June-2: There is no difference between using IIS Server / ISS Express (except of the temp-folder located in the user-dir. \AppData\Local\Temp).

      UPDATE June-11: At least this is fixed now: "C. Lo May 11, 2016 2:59 PM", exception without useful content while calling CR-method. It is a System.Threading.ThreadAbortException error.

      -> Instead of calling crystals ExportToHttpResponse()-method, this works as mentioned in , from the year 2011 (my implementation differs a bit):

      Stream crstream = crReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);//, System.Web.HttpContext.Current.Response, true, fileName);

      Response.ContentType = "application/pdf";

      Response.AddHeader("content-disposition", "attachment; filename=\"" + fileName + ".pdf\"");

      byte[] buffer = new byte[4096];

      int count = 0;

      while ((count = crstream.Read(buffer, 0, buffer.Length)) > 0) //this provides a correct value in HTML headerfield "Content-Length"


      Response.OutputStream.Write(buffer, 0, count);




      //Response.End(); <--this line produces a similar error like ExportToHttpResponse() -> "ThreadAbortException: Thread has been aborted."

      Meanwhile any further hints or ideas?


      C. Lo

      Message was edited by: C. Lo: solution added for System.Threading.ThreadAbortException

  • Jul 07, 2016 at 12:42 PM

    There are changes due to Crystal Report v13.0.17 for .NET.

    The memory leak is still present, but smaller.

    Summary of this thread:

    * I am using the Release-build and the latest CR-version for .Net.

    * I am releasing the CR-objects correctly (same results with using() and explicit dispose()).

    * I am using all the suggested GC.Collect()-calls.

    * The test-reports are prepared according to Dons suggestions.

    Unfortunately that all has not improved anything.


    * The mentioned website-problems have been fixed in v13.0.17 (files in temp-folder) / solved by a workaround as described in this thread ("ThreadAbortException").


    * Memory leak in windows service:

    System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 138035200

    System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 101011456

    <...creating 500 pdfs...>

    System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 148779008

    System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 107872256

    Memory consumption is growing meanwhile

    about +10 MByte (initial: +12 MByte) for WorkingSet64, and

    about +6 MByte (initial +13 MByte) for PrivateMemorySize64

    per 500 created PDFs.

    Do you need more infos/which further actions could I do?


    C. Lo

    Add comment
    10|10000 characters needed characters exceeded