Memory Issue when Optimizing large PDF

Hi

We are combining 1000s of small (average 100-150kb each) A4 pngs into a single PDF. This works fine but when we run the following:

        pdf.OptimizeResources(new Aspose.Pdf.Document.OptimizationOptions()
        {
            RemovePrivateInfo = true,
            AllowReusePageContent = true,
            LinkDuplcateStreams = true,
            RemoveUnusedObjects = true,
            RemoveUnusedStreams = true,
            CompressImages = true,
            ImageQuality = 50,
        });
        pdf.Optimize();

to optimize we are hitting memory issues.

The application server has 1.75GB of memory and it’s fine with 2000 pages but crashes with 3000 pages however if we up the memory to the next size 3.5GB then the PDF saves fine.

Given the final PDF for the 3000 page pdf is only about 45MB I’m confused as to why it should be blowing the memory.

Additionally when I run this on a local machine for 3000 images with bucket loads of memory it happily swallows 3GB before it even gets to the optimize, then during optimize it uses another 1GB, the final save doesn’t seem to impact the memory usage that much.

We add the images to each page like so (to avoid having them in memory was my hope):

            Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
            image1.File = tempfile;
            page.Paragraphs.Add(image1);

Is there anything else we can do to reduce the memory usage or is this a memory leak?

Thanks

Simon
PS: I recently updated to version 17.6 of the Aspose.Pdf library so it’s fairly recent.

@simon.fairey

Thanks for contacting support.

We have already noticed that API took time, more than expected, while generating PDF of PNGs with optimization process. However we are unable to notice the memory consumption issue in our environment. Please note that, we have tested the scenario with Aspose.Pdf for .NET 17.7, as it is most recent version of the API.

Would you please try the scenario again at your end with latest version of the API and in case if you still face any issue, please share your environment details (i.e Operating System, Application Type, Target Framework Version, etc.), so that we can test the scenarion in specified environment and address it accordingly.