We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Memory leaks in Aspose PDF NET

We have a following lines of code to check the memory usage and dispose in Aspose PDF NET 22.3.0

string[] _pdfFiles = new string[] {
        "Data/sample_45_mb.pdf",
        "Data/Nikon16mb.pdf",
        "Data/24mb.pdf",
         "Data/sample_45_mb.pdf",
        "Data/Nikon16mb.pdf",
        "Data/24mb.pdf",
        "Data/sample_45_mb.pdf",
        "Data/Nikon16mb.pdf",
        "Data/24mb.pdf",
        "Data/sample_45_mb.pdf"
        };
foreach (var fileName in _pdfFiles)
            {
                using (var file = File.OpenRead(fileName))
                {
                    using (Document document = new Document(file))
                    {
                        using (MemoryStream textStream = new MemoryStream())
                        {
                            Aspose.Pdf.Devices.TextDevice textDevice = new Aspose.Pdf.Devices.TextDevice();

                            Aspose.Pdf.Text.TextExtractionOptions textExtOptions = new
                             Aspose.Pdf.Text.TextExtractionOptions(Aspose.Pdf.Text.TextExtractionOptions.TextFormattingMode.Raw);
                            textDevice.ExtractionOptions = textExtOptions;
                            textDevice.Process(document.Pages[1], textStream);
                            string extractedText = Encoding.Unicode.GetString(textStream.ToArray());
                        }
                    }

                }
            }

We are observing the the Aspose is not disposing memory even after completion of the execution of above code (foreach loop).

Ex: In Performance profiler we saw the Aspose is still using 200+ MB of memory after this code execution.

Link for the above files



Any suggestions much appreciated.

@cpaperless

When PDF document is closed, all the DOM data is purged from memory during the next garbage collector cycle. Please note that the memory may not be released until you close the application.

Could you please share all steps how are you checking the memory leakage?

Please find the VS performance profiler output file
You can view this in VS 2019 or above.
This is the output of the above code in terms of memory usage and dispose.

ReportAsposeMemoryLeak.zip (1.6 MB)

@cpaperless

We have logged this problem in our issue tracking system as PDFNET-51685. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.