Improve Memory Optimization | Memory Performance | Avoid Memory Leak & OutOfMemory Exceptions | Convert Word to PDF C# .NET

We just updated to 20.2 from 14.8. Now our process does not release memory or at least does not release it fast enough and eventually crashes with an out of memory exception.

Our process has been running for years without this issue, no other changes were introduced at the time of our upgrade.

We upgraded because we thought the newer version would be better. We were wrong.

Please advise, what are you doing to address the memory leak and when will improvements be made available to customers who need them?

Beyond setting, MemoryOptimization = true, what else can we do to reduce the problem?

On Sunday we updated from Aspose.Words 14.8 to 20.1, then when our servers ran out of memory (were fine on 14.8) on Monday we saw the optimizations so quickly updated to 20.2.
Moving to 20.2 helped, we could see memory being returned whereas with 20.1 it was not. However the memory leak is only improved, not fixed, we still see the memory continuing to rise and eventually get OutOfMemory exceptions.
It’s a very busy server but as I said, we never saw this with 14.8.
Is work continuing with improvements to memory leaks?

On Sunday we updated from Aspose.Words 14.8 to 20.1, then when our servers ran out of memory (were fine on 14.8) on Monday we saw the optimizations so quickly updated to 20.2.
Moving to 20.2 helped, we could see memory being returned whereas with 20.1 it was not. However the memory leak is only improved, not fixed, we still see the memory continuing to rise and eventually get OutOfMemory exceptions.
It’s a very busy server but as I said, we never saw this with 14.8.
Is work continuing with improvements to memory leaks?

@ptazure,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document you are getting this problem with
  • Please create a standalone simple Console application (source code without compilation errors) that helps us to reproduce your 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 and provide you more information. Thanks for your cooperation.

I believe the ‘leak’ (not actually a leak but that is the way it presents) occurs when a large report is generated because the object arrays created to generate the report end up on the LOH (Large Object Heap)

From Microsoft Docs:

If an object is greater than or equal to 85,000 bytes in size, it’s considered a large object. This number was determined by performance tuning. When an object allocation request is for 85,000 or more bytes, the runtime allocates it on the large object heap.

Once an object is put on the LOH it is rarely cleaned up, so if many large reports are generated it looks like there is a memory leak.

When I use this approach it helps significantly to increase available memory. But forcing a GC, particularly when also compacting the LOH, is not ideal (all other threads are blocked until this completes).

The way you use object arrays must have changed from v14.8 (where our reports did not exhibit a memory leak) to 20.2.

Are you doing any work to reduce the potential size of object arrays and thus reduce the number of those arrays that end up on the LOH?

@ptazure,

Unfortunately, it is difficult to say what the problem is without the document and console application (please see my previous post). We need your document and source code to be able to reproduce the exact problem on our end. Please note that it is safe to attach files in the forum. If you attach your documents/files here, only you and Aspose staff members can download them. You can also remove any sensitive information by replacing it with dummy data instead. We will be able to start investigation into your scenario as soon as you provide required resources to reproduce. Thanks for your cooperation.

aspose-reports-sample.zip (4.0 MB)

Files attached. We have a couple of dozen more templates, I had to remove them because the max size file I can upload is 5MB (though the error message says 50000kb is allowed). I can send more separately if that helps.
Our code was written for version 14.8 so we’re hoping it is something our side that we can improve.
I have also included some screen shots from some memory profiling we have done, it shows an constant increase of an object in the Aspose library, we can’t tell what the object type is because of obfuscation.

@ptazure,

I am afraid, your project is causing lots of compile time errors on our end (see screenshot Compiler errors.zip (88.1 KB)). We request you to please resolve those errors and reattach simplified console application without those compilation errors here for testing. Thanks for your cooperation.

Ah sorry it was late at night when I did this, I thought it said it did not have to compile :frowning:
Is simply compiling enough? I presume it doesn’t need to actually run?

@ptazure,

It would be great if you please provide a runnable simplified console application that helps us to reproduce your problem on our end. Thanks for your cooperation.

aspose-reports.zip (553.8 KB)
New build has one working report. Just sample data.

@ptazure,

We tested your project with Aspose.Words for .NET 20.3 (latest version) and were able to generate a 10 pages PDF report without observing any spikes in memory usage on our end. Can you please try the latest version of Aspose.Words for .NET i.e. 20.3 on your end and see if the same project (that you attached here) causes out of memory exception?