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 : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PDF Memory leak?

Thread ID:

Created:

Updated:

Platform:

Replies:

123871 Apr 28,2016 07:18 AM UTC Apr 29,2016 01:12 PM UTC UWP 2
loading
Tags: Pdf
Romane Donnet
Asked On April 28, 2016 07:18 AM UTC

Hi there!

Just began on syncfusion PDF and wanted to ask a quick question :

I'm trying to generate a large amount of pages into a PDF. Here's my code :

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
        
            var watch = System.Diagnostics.Stopwatch.StartNew();
            PdfDocument doc = new PdfDocument();
            doc.EnableMemoryOptimization = true;

            for (int i = 0; i < 5000; i++){
                await GeneratePDF(doc, i);
                Debug.WriteLine("doc " + i.ToString());
            }

            using (MemoryStream stream = new MemoryStream()){
                await doc.SaveAsync(stream);
                doc.Close(true);

                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                Debug.WriteLine("generation in " + elapsedMs.ToString() + "ms");


                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                StorageFile stFile = await local.CreateFileAsync("test.pdf", CreationCollisionOption.ReplaceExisting);
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite)){
                    using (Stream st = fileStream.AsStreamForWrite()){
                        st.SetLength(0);
                        st.Write((stream as MemoryStream).ToArray(), 0, (int)stream.Length);
                        st.Flush();
                    }
                }
                stream.Flush();
            }
        }

        public async Task GeneratePDF(PdfDocument doc,int index)
        {
            PdfPage page = doc.Pages.Add();
            PdfGraphics g = page.Graphics;
            PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36);
            for(int i = 0;i < 1000; i++){
                g.DrawString("Hello world!", font, brush, new PointF(20, 20+i));
            }
        }

And here's what i'm seeing with the memory :




How can I free up the RAM after the generation?

Romane Donnet
Replied On April 28, 2016 07:24 AM UTC

Apparently the image doesn't load in the forum

Memory Leak image

Chinnu Muniyappan [Syncfusion]
Replied On April 29, 2016 01:12 PM UTC

Hi Donnet, 

Thank you for contacting Syncfusion support. 

We have created a simple sample without using any of the syncfusion assemblies, and here also we getting the same memory behavior , so we suspect this the actual behavior of the visual studio diagnosing tool, please refer the below sample for more details. 

And also we have tried your sample to ANTS Memory Profiler, we are not getting any memory leak, please refer the below screenshot. 
 

Please let us know if you have any concern. 

Regards, 
Chinnu 


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

;