Possible memory leak in PDFTron .net SDK?

Product: PDFTron

Product Version: 9.4

Please give a brief summary of your issue:
(Think of this as an email subject)

While debugging a recent issue I noticed this code within the PDFTron .net SDK:

public unsafe void Save(Stream stm, SDFDoc.SaveOptions flags)
{
uint flags2 = System.Convert.ToUInt32(flags);
PDFNetException.REX(PDFNetPINVOKE.TRN_PDFDocSaveMemoryBuffer(mp_doc, flags2, out var result_buf, out var out_buf_size));
byte* pointer = (byte*)result_buf.ToPointer();
using (UnmanagedMemoryStream unmanagedMemoryStream = new UnmanagedMemoryStream(pointer, out_buf_size.ToUInt32()))
{
if (stm.CanSeek)
{
stm.Position = 0L;
}

            if (unmanagedMemoryStream.CanSeek)
            {
                unmanagedMemoryStream.Position = 0L;
            }

            unmanagedMemoryStream.CopyTo(stm);
        }

        GC.KeepAlive(this);
    }

It appears that here, PDFNetPINVOKE.TRN_PDFDocSaveMemoryBuffer is returning an unmanaged buffer, and UnmanagedMemoryStream is being used to copy the contents of that buffer to the stream passed in to the Save method.
I don’t see the unmanaged buffer result_buf being freed. The documentation to UnmanagedMemoryStream does not state that it will free the buffer passed to it. Therefore it would seem that the memory allocated by TRN_PDFDocSaveMemoryBuffer is being leaked, or am I missing something?
I ask because we had to roll back a recent production deployment which makes extensive use of PDFTron, and the issues seemed to be resource-related.

Best regards,

Peter

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

Please provide a link to a minimal sample where the issue is reproducible:

I am unable to reproduce any such issue, and no one else has reported this.

For me to investigate further please modify one of our samples to reproduce the issue and send me the modified code.

Hi Ryan. I created a simple project to save a PDF to a memory stream repeatedly and observed memory usage go up and up. After 4 minutes it does seem to plateau. However I confirmed that each time TRN_PDFDocSaveMemoryBuffer is called a new buffer is allocated.

Seems I can’t attach zip files here. Please let me know how and I will provide the sample project.

After 4 minutes it does seem to plateau.

That implies that there is no leak, if there was, it would always keep going up.

The .NET GC doesn’t have to release everything, it can hold onto things, for performance reasons.

we had to roll back a recent production deployment which makes extensive use of PDFTron, and the issues seemed to be resource-related.

Could you please go into full details on this.
When did this error start happening? What changed at that time?
What exactly went wrong?
Please provide screenshots/error messages/logs etc.