PDF export memory consumption

Posted by: snellcb on 24 August 2023, 3:08 am EST

    • Post Options:
    • Link

    Posted 24 August 2023, 3:08 am EST

    I have an application that was updated to v17.0.2 last February, and then recently update to v17.1.2 a couple weeks ago. After the last update, memory consumption for exporting section reports to PDF skyrocketed. A 1,500 page, 300MB report now maxes out RAM on 32GB server. This either causes “Insufficient memory to continue the execution of the program” exceptions or takes forever to run while grinding other activities on the server to a halt.

    I tried updating AR with the latest NuGet packages that post-date the v17.1.2 release (e.g., GrapeCity.ActiveReports.Core.Drawing.Gc v3.6.2, GrapeCity.Documents.Pdf v6.2.1) and now cannot export PDFs because of the following exception (tested with two different applications, both .NET 4.8 ASP.NET MVC web apps running x64 mode):

    Method not found: 'System.​Collections.​Generic.​IDictionary

    2{System.​String,GrapeCity.​Documents.​Pdf.​Destination} GrapeCity.​Documents.​Pdf.​GcPdfDocument.​get_NamedDestinations()'.​ at GrapeCity.​ActiveReports.​Core.​Export.​Pdf.​Section.​PdfExport.​Export(IEnumerable
    1 pages, BookmarksCollection bookmarks, IDictionary
    2 pagesMap, IDictionary
    2 resources, PdfSettings settings)

    at GrapeCity.​ActiveReports.​Core.​Export.​Pdf.​Section.​PdfExport.​Export(IEnumerable
    1 pages, BookmarksCollection bookmarks, IDictionary
    2 pagesMap, Stream stream, PdfSettings settings)

    at GrapeCity.​ActiveReports.​Export.​Pdf.​Section.​PdfExport.​ExportCore(SectionDocument document, Stream stream, String pageRange)

    Any ideas on how to resolve the memory issue?

    Thanks

  • Posted 26 August 2023, 4:05 am EST

    Hi Charles,

    I would suggest you to follow the following steps to fix the errors you are facing after upgrading to latest version:

    1. Download and Install ActiveReports 17.1.2. You may use the following link to download ActiveReports 17.1.2: Download
    2. Open your project in Visual Studio 2022(or 2019).
    3. Go to Tools>Convert To ActiveReports 17. This will re-add all the compatible packages using the installed version of ActiveReports 17.

    As for the memory consumption issue, I tested this issue at our end and I wasn’t able to reproduce this issue at my end. Please share the following details so we can reproduce this issue at our end and report this to the development team if need be:

    • A Runnable sample application reproducing the issue.
    • A Sample file and Dummy data to test with.
    • A Screenshot of the OOM Error.

    You may edit the attached sample application such that it reproduces the issue and send it back to us for further investigation.

    WebViewer.zip

  • Posted 30 August 2023, 1:32 am EST - Updated 30 August 2023, 1:37 am EST

    Thanks for the demo app. I’ve attached a version with a new section report that causes the out-of-memory exception shown in the attached screenshot. Just run the app and click the “PDF Memory Test” link on the default page.

    The section report uses a picture control to display an embedded form like the application in production experiencing this issue. This embedded-form approach worked fine for reports with 500-1,500 pages up until v17.1.2. (v.17.0.2 was okay). Now, running it with a “data set” of 100 items (to create 100 pages) causes an exception.

    The report will run okay using a data source with 10 items but fails with 100 (on a Win 10 pc with 32GB RAM of which about 50% is in use). If you don’t see the out-of-memory exception, increase the size of the data source in Download.aspx.cs.

    Note also that the section report resx file has duplicate entries for “picture1.ImageBaswe64String”. I’ve noticed that resx files often end up with duplicate entries like this. It doesn’t break the reports - just an FYI.

    GrapeCity WebViewer.zip

  • Posted 31 August 2023, 4:40 pm EST

    Hi Charles,

    Thank you for the sample! Upon trying to run your sample we were getting some exceptions related to the ‘System.Memory’ package, upon reinstalling the package your project runs as expected (without any OOM exception) and generates the PDF (refer to the attached video).

    We ran your project on a Win-19 PC with 16GB of RAM. The total memory consumption by your project was around ~4GB.

    As you are working with images in your report that consume a lot of memory and slow the processing time for the report, further PDF export performs their own comparisons to detect duplicate images we suggest you check our Optimize Section Report documentation page to further optimize your reports.

    We have also attached the updated sample of your project, you may run/modify the same as per your requirements.

    Regards,

    Anand

    CustomersSampleVideo.mp4

    GrapeCity WebViewer Updated.zip

  • Posted 1 September 2023, 4:23 am EST

    Thanks for the updated sample, but it throws the same error as the one I provided you. It doesn’t appear related to the System.Memory library per the exception detail I provided early (snippet below):

    OutOfMemoryException: Insufficient memory to continue the execution of the program.

    System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb) +12997603

    GrapeCity.Documents.Imaging.GcBitmap.CreateImage(Int32 pixelWidth, Int32 pixelHeight, Boolean opaque, Single dpiX, Single dpiY) +228

    Instead, it’s occurring in the call to Marshal.AllocHGlobal inside of GcBitmap.CreateImage(). Marshal.AllocHGlobal is in mscorlib.dll (System.Runtime.InteropServices namespace).

    Did you try running the report with more pages? It seems to be an issue NOT related to overall memory availability but instead to improper handling of unmanaged resources related to image generation for the PDF export.

    Thanks,

    Chuck

  • Posted 4 September 2023, 7:37 pm EST

    Hi,

    > Thanks for the updated sample, but it throws the same error as the one I provided you.

    Thanks for the clarification. We also experienced this issue initially but after updating the packages using Tool > Convert to ActiveReports 17, the report was being exported with no issue till 1000 pages but threw OOM Exception after that. This seems to be a bug in the latest version. I have escalated this issue to our development team and will revert you back once I have any update from them on the same.[AR-31508]

  • Posted 6 September 2023, 12:10 am EST

    Hi Chuck,

    Thanks for bringing this to our attention!

    We have received an update from our development team. The fix to this issue will be available in the version v17.2.1. The ETA is by the end of November 2023. Thank you for your patience. For now, the workaround would be to change the Compatibility Mode of the report from CrossPlatform to GDI and the report export should work with no issues.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels