Syncfusion.Pdf memory leak.

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?


1 Reply

PH Praveenkumar H Syncfusion Team 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 


Loader.
Up arrow icon