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

Notification

Icon
Error

Options
Go to last post Go to first unread
tross2  
#1 Posted : Tuesday, August 10, 2021 11:35:33 AM(UTC)
tross2

Rank: Newbie

Groups: Registered
Joined: 8/10/2021(UTC)
Posts: 3

We're experiencing a memory leak when loading documents that are unable to load due to being corrupt or invalid format.

Reproduction:
1. Call PdfDocument.Load() on an invalid format PDF.
2. Check the CallbackManager._list and the entry for the GetBlockCallback still exists. This GetBlockCallback still retains a reference to the PdfCustomLoader, which is not properly disposed of. This is because the PdfDocument has not been created, and handed the PdfCustomLoader.

The real issue comes if you are relying on local stream to be garbage collected after it's PdfDocument from PdfDocument.Load() has been disposed. PdfDocument stop referencing the local stream, but PdfCustomLoader does not. Since, PdfCustomLoader is around indefinitely, the memory leak is the size of the PDF.

If you dispose of the local stream, the leak is less, but still exists.

Edited by user Tuesday, August 10, 2021 4:59:06 PM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Wednesday, August 11, 2021 2:45:27 AM(UTC)
Paul Rayman

Rank: Administration

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

Thanks: 5 times
Was thanked: 121 time(s) in 118 post(s)
Which version are you using? As I remember, a similar issue was fixed in one of the previous versions.
tross2  
#3 Posted : Wednesday, August 11, 2021 8:46:19 AM(UTC)
tross2

Rank: Newbie

Groups: Registered
Joined: 8/10/2021(UTC)
Posts: 3

We're using the nuget package Pdfium.Net.SDK v4.56.2704
tross2  
#4 Posted : Wednesday, August 11, 2021 8:54:53 AM(UTC)
tross2

Rank: Newbie

Groups: Registered
Joined: 8/10/2021(UTC)
Posts: 3

I updated to latest (v4.57.2704) and still see the issue. I believe the fix would be in the PdfDocument Load (Stream stream....) method. You could wrap a try catch around the the call to PdfDocument.Load(loader). If you catch any exception, unsubscribe the event handler from LoadBlock, and dispose of the loader, then rethrow the exception.
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.