Aspose.Pdf .NET memory leaks in TextStamp

Hi awesome people at Aspose!

I have discovered a memory leak when working with TextStamp. When working with Large Pdf files, if you apply a text stamp on each page, you end up with a lot of “Generation 2” objects that don’t get cleared even after disposing the document and/or Freeing the Memory. See the attached image and the sample code to reproduce this issue.

Aspose.Pdf .NET version 21.5.0

Appreciate the help!

Regards,
Zeeshan

Memory_Leak.jpg (518.2 KB)

@zeeshan1

Please try to call Page.Dispose() method after adding a stamp on each page in foreach loop and let us know in case you still face a memory consumption issue.

Hi Asad,

Thanks for replying during your Eid holidays, hope you are having a good time. I have tried your kind suggestion but it has no effect on the memory footprint. I am seeing the same behavior of “Generation 2 objects” occupying more than 500MB.

Regards,
Zeeshan

@zeeshan1

Thanks for your kind feedback.

Could you please share the environment details in which you are running the API i.e. VS Version, OS name and version, RAM Installed, Application Type, etc.

I am using the following

  • OEM Developer license with Apose.Pdf for .NET via nuget.
  • VS 2019 community edition version 16.0.9
  • I have tried both Windows 10 Professional, and Ubuntu 21.04 via docker, both have this problem
  • In production we have an ASP.NET 3.1 project, but a console .net core project (sample code) also has the same problem.
  • We used ANTS memory profiler to test for this memory leak.

I have already provided the sample application so please test it if you can.

@zeeshan1

We have noticed that memory consumption was >700 MB in our environment while testing the scenario. Therefore, have logged an issue as PDFNET-49929 in our issue management system. We will investigate the ticket in detail and keep you posted with the status of its resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi Asad,

Thanks for all your help. Is there a scheduled date for this fix to be released. Our servers are taking a toll with pods getting evicted due to excess memory usage. We can manage it through redundancy for now but would be great to know when a fix is coming.

Regards,
Zeeshan

@zeeshan1

We will surely resolve the earlier logged ticket. However, it will be investigated and resolved on a first come first serve basis. Moreover, the performance related issues are complex in nature and they take significant amount of time to get fixed. Nevertheless, we will let you know in this forum thread as soon as some definite updates are available regarding ticket resolution. Please give us some time.

We are sorry for the inconvenience.

Hi Asad,

I definitely appreciate how responsive this forum is and how complicated memory leaks can be to fix. So thank you for all the help in this regard. Is there a way to track the progress of this issue. We are eagerly waiting for this fix.

Regards,
Zeeshan

@zeeshan1

The ticket has been logged in our issue management system and you cannot access it. However, you can see the status of the ticket at the bottom of the thread where the linked tickets are shown. Furthermore, we will keep you posted about the status of the ticket resolution within this forum thread.

Dear Asad,

Can we expedite this please. We are willing to get on a paid support incident if it gurantees a quick resolution. Please let me know. Thanks

@zeeshan1

Please note that priority support does not guarantee any immediate solutions. However, it does expedite the investigation process in terms to get a reliable ETA quicker. Also, the issues logged under paid support model are dealt with high priority and on urgent basis. Furthermore, you can login to helpdesk using same email address with which you have subscribed to paid support and create a topic there with the reference to ticket ID logged here. Your issue will be escalated to highest priority.

@zeeshan1

We have recently made some improvements in the API and with the latest version of the API (23.12), below code snippet consumes only 230MB of memory which is quite better in comparison to >700MBs.

using var doc = new Document(dataDir + "PdfFile.pdf");

var bkStamp1 = new TextStamp("Hello1")
{
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top,
    Width = 400,
    Height = 100,
    LeftMargin = 10,
    BottomMargin = 10
};

var bkStamp2 = new TextStamp("Hello2")
{
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top,
    Width = 400,
    Height = 100,
    LeftMargin = 50,
    BottomMargin = 50
};

var bkStamp3 = new TextStamp("Hello3")
{
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top,
    Width = 400,
    Height = 100,
    LeftMargin = 50,
    BottomMargin = 100
};

var bkStamp4 = new TextStamp("Hello4")
{
    HorizontalAlignment = HorizontalAlignment.Left,
    VerticalAlignment = VerticalAlignment.Top,
    Width = 400,
    Height = 100,
    LeftMargin = 10,
    BottomMargin = 2000
};

foreach (var page in doc.Pages)
{
    bkStamp1.Put(page);
    bkStamp2.Put(page);
    bkStamp3.Put(page);
    bkStamp4.Put(page);
    page.Dispose();
}

doc.Save(dataDir + "output.pdf");