Hello.
We use Aspose.PDF for .Net for processing many incoming user pdf files. We add some text to document using TextBuilder. We have noticed that memory consumption constantly grows over time. Here is code that demonstrates issue:
for (int i = 0; i < 10000; i++)
{
Document doc = new Document("input.pdf");
#region Code from https://reference.aspose.com/pdf/net/aspose.pdf.text/textbuilder/appendtext/
Page page = (Page)doc.Pages[1];
// create text fragment
TextFragment tf = new TextFragment("main text");
tf.Position = new Position(100, 600);
// set it's text properties
tf.TextState.FontSize = 5;
tf.TextState.Font = FontRepository.FindFont("TimesNewRoman");
tf.TextState.BackgroundColor = Color.LightGray;
tf.TextState.ForegroundColor = Color.Red;
// add one more segment to text fragment's Segments collection
TextSegment segment2 = new TextSegment();
segment2.Text = "another segment";
tf.Segments.Add(segment2);
// create TextBuilder object
TextBuilder builder = new TextBuilder(page);
// append the text fragment to the Pdf page
builder.AppendText(tf);
#endregion Code from https://reference.aspose.com/pdf/net/aspose.pdf.text/textbuilder/appendtext/
doc.Dispose();
/* uncomment to view memory stats in console
if (i % 100 == 0)
{
GC.Collect();
GCMemoryInfo memoryInfo = GC.GetGCMemoryInfo();
Console.WriteLine($"{DateTime.Now} iteration: {i}, committed: {memoryInfo.TotalCommittedBytes.ToString("N1", CultureInfo.InvariantCulture)}");
} */
}
This code shows constant memory consumption growth on attached document
input.pdf (175.4 KB)
Same code can work fine on other documents.
We noticed this behaviour in versions 23.9.0-23.11.1. In 23.8.0 works fine.
We run application using .net 6.0.
Perhaps we are missing something or is this really an issue?
Thank you for your help in advance!