Free Support Forum -

Out of memory exception in Aspose.Pdf.Document.OptimizeResources

I am using Aspose.PDF 18.6 to produce PDFs that include 3-5 relatively large PNG files (between 100 and 500KB) - not massive. Every once in a while, I have started seeing the following errors:

System.ArgumentException: Invalid image stream (Out of memory.)
   at Aspose.Pdf.XImageCollection._(Stream _, Int32 _)
   at Aspose.Pdf.Document._._(OperatorCollection _, Resources _)
   at Aspose.Pdf.Document._._(Document _)
   at Aspose.Pdf.Document._(OptimizationOptions _)
   at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)

This error is cropping up when calling OptimizeResources. The optimize options are as follows:

optimization.LinkDuplcateStreams = True
optimization.RemoveUnusedObjects = True
optimization.RemoveUnusedStreams = True
optimization.CompressImages = True
optimization.ImageQuality = 80

The images have been added as image streams, but all the streams have been tidied up by this point.

This error has only started happening recently and has only happened a few times against thousands of successful processing. The issue is not terminal - i.e. the process can re run the same set up with no issues.

Is this a memory leak in the way Aspose.PDF is marshalling resources?




Thank you for contacting support.

Please note that we need to reproduce the problem in order to investigate it in our environment. Kindly share a sample file which may reproduce this issue. Moreover, also mention if you have made some recent changes after which it started to occur, for example, if you have upgraded to latest version. Please mention respective details so that we may try to reproduce and investigate it in our environment.

Furthermore, before sharing requested data, please ensure using Aspose.PDF for .NET 18.10 in your environment.

Hi @Farhan.Raza - thanks for your reply. Unfortunately I cannot share the documents in question with you for privacy reasons. I cannot also easily upgrade the environment affected from 18.6 to 18.10.

We have had this happen several times today. So far we have been unable to recreate this in our other environments. We are looking to see if we can recreate this with a document that I can share with you.

Do you know of any memory leaks with this particular part of the product?




Please note that the attachments over forums are accessible to thread owner and Aspose staff only. However, you may also upload it to Google Drive, Dropbox etc and share the link with me in a private message. You may click on my username and send a message. Please take all the time you need and then share respective data with us as per your convenience.

About memory leak, we did not notice such problem otherwise it would have been rectified already. We will further update you once the problem is reproduced and investigated in our environment.