We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.PDF "doc.OptimizeResources()" throws "Out of Memory" exception?


We are trying replace our “QuickPDF” component with “Aspose.PDF”.

We found another issue when we call OptimizeResources() function of Document object. Below is the code that we are using.

private void OptimizeDocument(Document documentToOptimize)
Aspose.Pdf.Optimization.OptimizationOptions options = new Aspose.Pdf.Optimization.OptimizationOptions()
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
AllowReusePageContent = true,
RemoveUnusedStreams = true,
UnembedFonts = false,

        options.ImageCompressionOptions.CompressImages = true;
        options.ImageCompressionOptions.ImageQuality = 100;// Should be 100 always else affects images appearance.
        options.ImageCompressionOptions.ResizeImages = true;

Below is the screen shot of stack trace.
stack trace Screenshot (216).png (261.1 KB)

I believe our production application where we merge 1500 pdf pages, throws this exception when it crosses 1.2GB of memory usage, so in order to replicate this you just need to increase the number of files to merge(may be >5k) and call the “OptimizeDocument” function later.

Also, we have observed a sudden spike in memory from 300MB to 1.2GB when this function is called.

Update: We are getting another exception some of the times (refer below screenshot).
Screenshot (218).png (220.4 KB)

Please review and provide us a solution as soon as you can.



Could you please attach the following resources here for testing:

  • Your input PDF.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

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

PS: To attach these resources, please zip and upload them.