Memory leak in 20.10.0

Our application memory spikes and never recovers when creating and saving aspose documents. We created a test case that does nothing but open a stream of bytes and write them with an Aspose Document to a file. The first picture is after the document has fallen out of scope and out of the stream using statement, and should be deallocated. The second picture is after an explicit GC.Collect(). There is no change in allocation, there are no references in our code to any of the objects, yet there are thousands of Paragraph, image, etc objects in memory that NEVER get deallocated. Here is the sample code that still produces a memory issue.

using (MemoryStream stream = new MemoryStream(bytes))
{
	Aspose.Words.Document doc = new Aspose.Words.Document(stream);
	doc.Save("C:/users/me/test.pdf", SaveFormat.Pdf);
}

GC.Collect();
after.png (37.8 KB)
before.png (37.5 KB)

@ajnahat,

Please upgrade to the [latest (21.3) version of Aspose.Words for .NET]https://releases.aspose.com/words/net/ and see how it goes on your end? In case the problem still remains, then please ZIP and attach the following resources here for testing:

  • Your simplified input Word document you are getting this problem with
  • A standalone simple Console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your scenario/issue and provide you more information.

This problem persists in the newest version. Here is the console app that demonstrates the issue.AsposeTest.zip (28.0 KB)

@ajnahat,

For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-21980. We will further look into the details of this problem and will keep you updated on the status of linked issue. We apologize for any inconvenience.

@ajnahat,

Regarding WORDSNET-21980, we have checked your application and not found any memory leaks. We ran the code that opens and saves the document in the loop (5000 iterations) and memory usage does not increase. But, you are right; memory is not fully released after processing the document, because Aspose.Words on first run initializes some internal static resources. For example, fonts are read once and are stored in static resource to improve rendering performance. So, we are going to close this issue as “Not a Bug”. Please let us know if we can be of any further assistance.

We are using Aspose.Words inside a web application, and we cannot restart the server to reclaim memory. Do you have a way to free up memory after converting a word document to pdf? If not, can you add a Deallocate method we could call to free up the memory?

@ajnahat,

We have logged your concerns in our issue tracking system and will keep you posted here on any further updates.

@ajnahat As Awais mentioned, Aspose.Words on the first run needs to initialize internal resources. These resources are kept while application is running. If Aspose.Words will initialize the mentioned resources on each run, this will significantly decrease document conversion performance. For example, see the following code and the results:

System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();

// When you run the conversion to fixed page formats first time,
// Aspose.Words inits the required resources and the conversion take more time than the subsequent conversions.
watch.Start();
Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");
watch.Stop();
Console.WriteLine("First execution takes {0}ms", watch.ElapsedMilliseconds);

watch.Reset();
watch.Start();
Document doc1 = new Document(@"C:\Temp\in.docx");
doc1.Save(@"C:\Temp\out.pdf");
watch.Stop();
Console.WriteLine("Second execution takes {0}ms", watch.ElapsedMilliseconds);

Results:

First execution takes 7918ms
Second execution takes 903ms

As you can see the first conversion takes much more time than the second. So, if each run of Aspose.Words in your application will be like the first run this significantly affect the conversion performance, that is much worse than keeping few MB in the memory.

It is not a few MB, it is hundreds of MB to multiple GB depending on our document. The first image is right before Document.Save. The second image is directly after. it grows from 800MB->1.5GB. The third image is several seconds after the app continues running after the method completes. The memory never gets deallocated. This is a relatively small test case compared to our potential document size, and the bigger documents exhibit the same behavior but with greater memory problems.

after save.png (47.0 KB)
before save.png (46.2 KB)
hundreds of mb not coming back.png (4.9 KB)

@ajnahat Thank you for additional information. But the project and the document you have attached did not allow us to reproduce the problem. The only remaining used memory is used by static resources. I run the conversion process in the loop and if document did not deallocate memory then memory consumption would continuously grow in the loop.
So please attach the document and the code that will allow us to reproduce the problem.

@ajnahat Have you managed to create an application that will allow us to replicate the memory leak issue? Since we cannot reproduce the problem on our side the issue WORDSNET-21980 will be closed as Not a Bug.

is this issue fixed in latest release?

@sbogisam As it was mentioned, the defect has been closed as Not a Bug. If you have a similar issue, please start a separate topic and create a simple application that will allow us to reproduce the problem. We will check the problem and provide you more information.

A post was split to a new topic: Memory leak in 22.10