logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
drbmay  
#1 Posted : Thursday, November 9, 2017 12:30:13 PM(UTC)
drbmay

Rank: Newbie

Groups: Registered
Joined: 11/9/2017(UTC)
Posts: 3
United States
Location: Portland, OR

During a stress test of keyword searching that uses roughly 10k words (yes, this is silly, I understand) and the memory usage rises every page searched and when I close the PDF file, the memory is not reclaimed. I can clone the PdfViewer control and dispose of it when I'm done with the file and the memory is still used. The only time the memory is reclaimed is when the application terminates. If I do not use the PdfPage.Text.Find call, I do not have memory issues, but I'm also not searching the PDF.

Visual Studio Community 2015
VB.Net
PDFium (current version) 3.11.3.2704
64 bit application


Code:

'// tb is a textbox with search phrases per line
'// PdfViewer1 is the PDFViewer control

If PdfViewer1.Document IsNot Nothing Then

    PdfViewer1.RemoveHighlightFromText()
    Dim intPagesCtr = PdfViewer1.Document.Pages.Count
    Dim currPage As PdfPage

    For i = 0 To intPagesCtr - 1
        currPage = PdfViewer1.Document.Pages(i)

        Dim parts As String() = tb.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        Dim found As PdfFind = Nothing

        For h = 0 To parts.Count - 1
            '// if the next line is commented out, there are no memory issues
            found = currPage.Text.Find(parts(h), FindFlags.MatchWholeWord, 0)
            If (found IsNot Nothing) Then
                PdfViewer1.HighlightText(i, found.CharIndex, found.CharsCount, Color.Yellow)
                Do While (found.FindNext())
                    PdfViewer1.HighlightText(i, found.CharIndex, found.CharsCount, Color.Yellow)
                Loop
            End If

        Next

        currPage.Dispose()
        currPage = Nothing
    Next
End If
drbmay  
#2 Posted : Thursday, November 9, 2017 12:32:16 PM(UTC)
drbmay

Rank: Newbie

Groups: Registered
Joined: 11/9/2017(UTC)
Posts: 3
United States
Location: Portland, OR

I can't add links to the source PDF to use and text file that lists the terms as the message board thinks it's spam.
Paul Rayman  
#3 Posted : Thursday, November 9, 2017 3:49:57 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 760

Thanks: 1 times
Was thanked: 92 time(s) in 91 post(s)
Hi,
Try to call found.Dispose() at the end of cycle iteration.
drbmay  
#4 Posted : Thursday, November 9, 2017 4:19:00 PM(UTC)
drbmay

Rank: Newbie

Groups: Registered
Joined: 11/9/2017(UTC)
Posts: 3
United States
Location: Portland, OR

Paul,

In one of my previous tests I had found.dispose() call in the code and it did not change the memory usage.

Below is the memory usage while PDFPage.Text.Find runs with the below code.
memusage.png (9kb) downloaded 16 time(s).

Updated test code:
Code:

'// tb is a textbox with search phrases per line
'// PdfViewer1 is the PDFViewer control

If PdfViewer1.Document IsNot Nothing Then

    PdfViewer1.RemoveHighlightFromText()
    Dim intPagesCtr = PdfViewer1.Document.Pages.Count
    Dim currPage As PdfPage

    For i = 0 To intPagesCtr - 1
        currPage = PdfViewer1.Document.Pages(i)

        Dim parts As String() = tb.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        Dim found As PdfFind = Nothing

            found = currPage.Text.Find(parts(h), FindFlags.MatchWholeWord, 0)
            If (found IsNot Nothing) Then

                PdfViewer1.HighlightText(i, found.CharIndex, found.CharsCount, color)
                Do While (found.FindNext())
                    PdfViewer1.HighlightText(i, found.CharIndex, found.CharsCount, color)
                Loop

                found.Dispose()
                found = Nothing
            End If

        Next

        currPage.Dispose()
        currPage = Nothing
    Next
End If
Paul Rayman  
#5 Posted : Tuesday, May 7, 2019 1:08:02 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 760

Thanks: 1 times
Was thanked: 92 time(s) in 91 post(s)
When there is a selected or highlighted text on the page, the page is not disposed, even if it is not currently visible in the viewer.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.