Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jul 08, 2022 5:34 pm

Currently using Spire.PDF v8.7.2.

I wrote a program which runs through lists of .pdf files and does the following:

1) Opens the original .pdf files
2) Creates a new .pdf file
3) Loops through the pages of the original .pdf file and copies each one to the new .pdf
4) Saves the new .pdf to a different location

As far as I can tell, everything is being Disposed of properly with Using statements. However, if I run this program through a large number of .pdf files, the running program takes up more and more memory until eventually either the program or the computer crashes. The larger the .pdf files being copied, the quicker this happens.

Shouldn't the memory used by the original and new .pdf files be freed back up upon closing them?

The following code runs through 1000 .pdf files (named sample_pdf_1.pdf through sample_pdf_1000.pdf) and basically copies them to another folder, 1 page at a time. I know there are easier ways of doing this, but copying is not my final objective. I will be eventually modifying the individual pages. However, just doing this results in the program using all available free memory and crashing, so moving to the next step is not an option using Spire.PDF at this time.

Sample Code:
Code: Select all
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Public Class Sample
    Public Sub CopyPDF()
        Dim InFolder As String = "c:\in_folder\"
        Dim OutFolder As String = "c:\out_folder\"
        Dim InFilename As String = String.Empty
        For i = 1 To 1000
            InFilename = "sample_pdf_" & i.ToString.Trim & ".pdf"
            Using OriginalPDF As PdfDocument = New PdfDocument
                OriginalPDF.LoadFromFile(InFolder & InFilename)
                Using NewPDF As PdfDocument = New PdfDocument
                    For pg = 0 To OriginalPDF.Pages.Count - 1
                        NewPDF.InsertPage(OriginalPDF, pg)
                    Next pg
                    NewPDF.SaveToFile(OutFolder & InFilename)
                End Using
            End Using
        Next i
    End Sub
End Class

cmichael_ph
 
Posts: 2
Joined: Tue May 31, 2022 5:15 pm

Mon Jul 11, 2022 9:42 am

Hi,

Thank you for your inquiry.
I simulated a thousand PDF documents and did an initial test, but didn't reproduce your problem. Please provide some information for further investigation. You can attach your file here or send it to us via email (support@e-iceblue.com). Thanks in advance.
1) Your test PDF documents.
2) Test environment, such as win10, 64bit.
3) Application type, such as Console App, .NET Framework 4.8.
In addition, the forum has 2MB limitation on attachment size. If your documents exceed this limit, please upload your it via Google Drive and share the download link.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Tue Jul 12, 2022 2:50 pm

1) Unfortunately, I cannot provide you with the .PDF files because of security reasons, but I will say they vary greatly in content and size. The issue with the program getting larger and larger happens no matter the size of the .PDF, but does increase faster when the .PDF files are larger.

2) I have tested this on both Windows 10 64bit and Windows Server 2016 64bit and experienced the same issue.

3) The application in question was a Console App using .NET Framework 4.5.2

cmichael_ph
 
Posts: 2
Joined: Tue May 31, 2022 5:15 pm

Wed Jul 13, 2022 10:14 am

Hi,

I simulated a large number of PDF documents (about 900MB) and did a test, but did not reproduce the problem of large memory consumption causing the program to crash. Note that memory consumption is also related to the complexity of the document structure. I suggest you try to release the NewPDF by calling the code below after saving the document.
Code: Select all
                    NewPDF.Close()
                    NewPDF.Dispose()

If the problem still exists, I guess your documents may contain some special data structure that consumes a lot of memory when parsed with our product. Please provide the following information for detailed investigation. We promise to keep your document confidential and we will not use it for any other purpose. You can send your file to us via email (support@e-iceblue.com). Thanks in advance.
1) Some sample PDF documents
2) Your project platform (X86 or X64 )
3) Computer's RAM (16GB)

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Mon Oct 31, 2022 7:14 am

Hi,

Regarding the issue you posted on our forum, has it been resolved? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF