High Memory Usage while Converting Slide to Image with Custom Size in Java

Hi Support,
I’ve observed very high memory usage while converting slide to image with custom size.

Code snippet (tests):

class AsposeTest {

    @Test
    void getThumbnail() {
        Presentation presentation = new Presentation(pptxFile());

        ISlide firstSlide = presentation.getSlides().get_Item(0);

        BufferedImage slideThumbnail = firstSlide.getThumbnail();

        assertThat(slideThumbnail.getHeight()).isEqualTo(108);
    }

    @Test
    void getThumbnailWithCustomSize() {
        Presentation presentation = new Presentation(pptxFile());

        ISlide firstSlide = presentation.getSlides().get_Item(0);

        BufferedImage slideThumbnail = firstSlide.getThumbnail(new Dimension(3000, 1600));

        assertThat(slideThumbnail.getWidth()).isEqualTo(3000);
        assertThat(slideThumbnail.getHeight()).isEqualTo(1600);
    }

    private InputStream pptxFile() {
        ClassLoader classLoader = getClass().getClassLoader();
        try {
            return new FileInputStream(classLoader.getResource("pptx-image-2mb.pptx").getFile());
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}

Presentation file: pptx-image-2mb.pptx.zip (2.0 MB)
Result from Profiler (JFR): AsposeTest_2023_07_13_164732.jfr.zip (673.0 KB)
Environment Details:

  • Java: openjdk 17.0.4.1
  • Aspose.Slides: 23.6
  • Heap settings: -Xms128m -Xmx2048mb (Xmx1024mb is not enough, tests end with OOM)

You can see from the attached example that 1GB of memory may not be enough to convert a presentation containing a 2mb image (using ISlide#getThumbnail). I also tested converting presentation containing text only, and it seems that big memory peaks are very related to images in slides.

I am also attaching graphs showing memory consumption during conversion of presentations that have a larger size:

  1. Presentation of size 30MB (1 slide with a 30MB image)
    image.png (9.3 KB)
    It needs around 3GB of memory.

  2. Presentation of size 70MB (4 slides with an image on each, in sizes of 10MB, 15MB, 20MB, 30MB):
    image.png (13.2 KB)

This is causing a huge memory consumption in our production environment, sometimes ending with OOM.

Could you please check if there’s a way of converting slides to images using less memory?

Please let me know if you need any other info from my end.

Thank you!

@ANDREA.FARRIS,
Thank you for contacting support. I am working on the issue you described and will get back to you as soon as possible.

@ANDREA.FARRIS,
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39246

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Please also share the following additional information and files:

  • OS version on which the tests were performed
  • the presentation files of size 10MB and 70MB you mentioned if it is possible (you can share a link to the files saved to file storage)

Hi @andrey.potapov
Thank you for your prompt response.

The information you asked for:

  • OS: macOS Ventura - Version 13.4 (22F66)

I did a typo, the presentations are of size 30MB and 70MB. I can upload them to a file storage. Would you recommend any free ones which are generally used on the forum?

EDIT: Grammar.

@ANDREA.FARRIS,
You can use Google Drive or Dropbox, for example.

Unfortunately, we have no access to the storages you mentioned.

70MB presentation is easy to re-create: 4 empty slides with an image on each, the images are in sizes of 10MB, 15MB, 20MB, 30MB. The images are with the extension ‘.jpg’.

Hope that helps.

@ANDREA.FARRIS,
Thank you for the explanation. I’ve forwarded your information to our developers.

@ANDREA.FARRIS,
Our developers have investigated the case. You are right, images usually consume most of the memory. In your sample presentation, 2MB (2 101 546) image on disk is not equal to 2 MB in RAM, because images are compressed on disk. An image usually uses 4 Bytes Per Pixel, the formula for calculating RAM is like this: height * width * BPP, in our case 3218 * 4219 * 4 = 54 306 968.

In addition, images in some cases need to be adapted to the size of the slide, for this need to draw them in other sizes, in fact, multiplying by 2 the required memory to store these images.

Unfortunately, there is no solution that will definitely prevent OOM from occurring. We suggest using IBlobManagementOptions as follows:

LoadOptions loadOptions = new LoadOptions();
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked);
loadOptions.getBlobManagementOptions().setTemporaryFilesAllowed(true);
loadOptions.getBlobManagementOptions().setTempFilesRootPath(resourcesOutputPath);
loadOptions.getBlobManagementOptions().setMaxBlobsBytesInMemory(329145600);

Presentation presentation = new Presentation(folderPath + "pptx-image-2mb.pptx", loadOptions);
1 Like