Protecting against OOM best practices

Hello,

We were surprised by the memory use of the Aspose.Words product since we’re using it primarily for conversion.
We will try to work around this memory use (due to the DOM I suppose), but our concern is how we can protect our
existing application and process from low memory conditions.

For example, I would not want an OOM situation caused by the Aspose suite’s allocations to interfere with
memory allocation for other parts of our application (e.g. view generation, storage layer, etc) which might
result in unpredictable behaviour for our users.

Do you have a recommended or best practice approach?
Is there a way to get a callback on allocations so we can monitor memory use?

We can wrap the libraries in a separate JVM instance, but that’s rather “brute force”. I’d prefer something
within our existing process.

Thanks!

@gregrwade,

Thanks for your inquiry. Please refer to the following articles:
C# Exception Handling Best Practices
Best practices to optimize memory in C#

Please note that performance and memory usage all depend on complexity and size of the documents you are generating.

In terms of memory, Aspose.Words does not have any limitations. If you’re loading huge Word documents into Aspose.Words’ DOM, more memory would be required. This is because during processing, the document needs to be held wholly in memory. Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

When the document is closed, all the DOM data is purged from memory during the next garbage collector cycle. Please note that the memory may not be released until you close the application.

We suggest you please use SaveOptions.MemoryOptimization property to optimize the memory performance. Setting this option to true can significantly decrease memory consumption while saving large documents at the cost of slower saving time. Hope this helps you.

Best Regards,
Tahir Manzoor

Tahir,

I think you may have missed my main concern. I don’t want the memory use to affect the rest of the application, so I’m looking for ways to protect against out of memory exceptions. Do you offer any callbacks for that, or have any recommended best practices for avoiding OOM in some predicative manner? Users will choose to transcode images of their own choosing, and we have no way from what I can tell to predict in advance how much memory will be needed.

Greg.

p.s. We’re using the Java variant.

@gregrwade,

Thanks for your inquiry. You can use try-catch blocks and respond against out of memory exception in catch block.

Sometimes Aspose.Words for Java throws OutOfMemoryError on Java. This is because the default Java heap space might not be enough for high memory spikes when processing some documents. In this case, the easy way to workaround is to increase the heap space for the JVM.

Usually, Aspose.Words needs 10 times more memory than the original document size to build a DOM in the memory.

Unfortunately, Aspose.Words does not offer any callback for exceptions. Could you please share the complete detail of your use cases? We will then log your requirement in our issue tracking system for implementation. Our product team will look into the possibility of implementation of your scenario.

Best Regards,
Tahir Manzoor