We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Syncfusion.Pdf memory leak.

Thread ID:

Created:

Updated:

Platform:

Replies:

126289 Oct 5,2016 01:32 PM UTC Oct 6,2016 12:36 PM UTC WinForms 1
loading
Tags: PDF
Dmitry
Asked On October 5, 2016 01:32 PM UTC

Hello!

 

We are using your Syncfusion.Pdf library and faced with a memory leak.

 

                      byte[] content = …;

byte[] xmlFormData = …;

 

                      using (var pdfInStream = new MemoryStream(content, false))

                      using (var pdfDocument = new PdfLoadedDocument(pdfInStream))

                      using (var xmlFormDataStream = new MemoryStream(xmlFormData))

                      {

                             pdfDocument.Form.ImportDataXFDF(xmlFormDataStream);

                             pdfDocument.Form.Flatten = true;

 

                             using (var pdfDocumentStream = new MemoryStream())

                             {

                                    pdfDocument.Save(pdfDocumentStream);

 

                                    pdfDocumentStream.Seek(0, SeekOrigin.Begin);

 

                                    return pdfDocumentStream.ToArray();

                             }

                      }

 

After running this code multiple times memory fills with a big amount of objects that can’t be garbage collected:

              Syncfusion.Pdf.Graphics.Fonts.StandardWidthTable       

              Syncfusion.Pdf.Graphics.Fonts.PdfFontMetrics

              Syncfusion.Pdf.Graphics.PdfTrueTypeFont

Service gets bigger and bigger and eventually hangs.

 

The reason is the static s_cache variable in Syncfusion.Pdf.PdfDocument class, that stores all the references to this objects:

 

 

The problem exists in 14.3451.0.49 library version.

Can you please assist us with this?


Praveenkumar H [Syncfusion]
Replied On October 6, 2016 12:36 PM UTC

Hi Dmitry, 

Thank you for using Syncfusion products, 

Can you please enable memory optimization in you code as given in the below code snippet, 

byte[] content = …; 
byte[] xmlFormData = …; 
 
using (var pdfInStream = new MemoryStream(content, false)) 
using (var pdfDocument = new PdfLoadedDocument(pdfInStream)) 
using (var xmlFormDataStream = new MemoryStream(xmlFormData)) 
{ 
pdfDocument.EnableMemoryOptimization = true; 
pdfDocument.Form.ImportDataXFDF(xmlFormDataStream); 
pdfDocument.Form.Flatten = true; 
 
using (var pdfDocumentStream = new MemoryStream()) 
{ 
pdfDocument.Save(pdfDocumentStream); 
 
pdfDocumentStream.Seek(0, SeekOrigin.Begin); 
 
return pdfDocumentStream.ToArray(); 
} 
} 
it will dispose all the resources when disposing the PdfLoadedDocument. 
 
Please try the above code snippet and let us know your result. 

Regards, 
Praveen 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;