Loading of 17MB PPTX in Java Consumes Nearly 1500MB of Memory

Hello, using Aspose Slides for Java 25.2. Loading of 17MB PPTX consumes nearly 1500MB of memory.

This code is used to

private static class HandleSaveProgress implements IProgressCallback {
    @Override
    public void reporting(double progressValue) {
        logJavaMemory(String.format("Memory at %.2f progress:", progressValue));
    }
}

private static void logJavaMemory(String msg) {
    Runtime runtime = Runtime.getRuntime();
    long usedMemory = runtime.totalMemory() - runtime.freeMemory();
    double usedMemoryInMB = usedMemory / (1024.0 * 1024.0);
    String usedMemoryString = String.format("Used Memory: %.2f MB", usedMemoryInMB);
    LOGGER.debug(msg + ": " + usedMemoryString);
}

LoadOptions loadOptions = new LoadOptions();
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked);
loadOptions.getBlobManagementOptions().setTemporaryFilesAllowed(true);
loadOptions.getBlobManagementOptions().setTempFilesRootPath(tempDirectory.toString());
loadOptions.getBlobManagementOptions().setMaxBlobsBytesInMemory(512 * 1024 * 1024); // 512MB

PdfOptions saveOptions = new PdfOptions();

saveOptions.setCompliance(AsposeContants.SLIDES_PDF_FORMAT);
saveOptions.setProgressCallback(new HandleSaveProgress());

Presentation presentation = new Presentation(inputFile, loadOptions);
try {
    presentation.save(outFile, SaveFormat.Pdf, saveOptions);
    logJavaMemory("Memory after saving pdf");
} finally {
    presentation.dispose();
}

Attaching the memory log.
AsposeSlidesMemory.zip (3.5 KB)

@AlesGregor

It seems that you are experiencing high memory consumption when loading a 17MB PPTX file using Aspose Slides for Java. This can happen due to the way presentations are managed in memory, especially with large files.

To mitigate memory usage, you can utilize the BlobManagementOptions in your LoadOptions. Specifically, setting the PresentationLockingBehavior to KeepLocked allows the presentation to be locked for the instance’s lifetime without loading it entirely into memory. This can help reduce the memory footprint significantly.

Here’s an example of how you can implement this:

LoadOptions loadOptions = new LoadOptions();
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked);
loadOptions.getBlobManagementOptions().setTemporaryFilesAllowed(true);
loadOptions.getBlobManagementOptions().setTempFilesRootPath(tempDirectory.toString());
loadOptions.getBlobManagementOptions().setMaxBlobsBytesInMemory(512 * 1024 * 1024); // 512MB

Presentation presentation = new Presentation(inputFile, loadOptions);
try {
    // Perform operations on the presentation
} finally {
    presentation.dispose();
}

By using the KeepLocked behavior, you can work with large presentations while keeping memory usage lower. Additionally, ensure that you dispose of the Presentation object properly to free up resources after you are done.

If you continue to experience issues, consider checking the memory logs you provided to identify any specific areas where memory usage spikes occur. This can help in further optimizing your code.

If you have any more questions or need further assistance, feel free to ask!

If you look more closely to the code example I have posted, you will see that the solution with loadOptions.getBlobManagementOptions(), that you are proposing, is the exactly same code as I am using. It is not helping.

@AlesGregor,
We are sorry that you encountered this problem. We would greatly appreciate it if you could share more details to help us investigate the issue. Please share the following:

  • sample presentation file
  • OS version on which the code was executed
  • JDK target version in your application project

Please also specify the compliance format in the following code line:

saveOptions.setCompliance(AsposeContants.SLIDES_PDF_FORMAT);

Hello @andrey.potapov ,

I observe this issue on different Linux distributions as well as on Windows using Java 11.

e.g.: Operating System: Linux 5.15.167.4-microsoft-standard-WSL2
Java version: 11.0.24

Operating System: Windows 10 10.0
Java version: 11.0.21

The AsposeContants.SLIDES_PDF_FORMAT = om.aspose.slides.PdfCompliance.PdfA2u;

Is there any way to share the source PPTx file with you privately?

I can share smaller PPTX file that consumes up to 1GB of memory.

blabla.zip (2.6 MB)

If the JVM memory is limited to 500MB ( -Xmx500m ) I see java.lang.OutOfMemoryError: Java heap space.

Best Regards
Ales

@AlesGregor,
Thank you for the details.

Please follow the instructions described in How to Send License File to Support Team to send us the source PPTX file. Then I will mark it as confidential data.

@AlesGregor,

I’ve reproduced the problem where converting a PowerPoint presentation to a PDF document consumes more than 1GB of memory.

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-39643

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.