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

Free Support Forum - aspose.com

Convert Tiff to PDF in java | memory leak in Aspose PDF 21.5


We are converting Tiff images to pdf using Aspose PDF Java 21.5 and noticed that there appears to be a memory leak because we get an out of memory exception. If I run the follow code snippet below with a tiff images 1000 times to simulate a 1,000 page document it runs out of memory.

BufferedImage image = ImageIO.read(new File(inputFilePath));
 boolean rotateToLandscape = image.getWidth() > image.getHeight();

    Document doc = new Document();
    Page page = doc.getPages().add();

    if (rotateToLandscape) {

    com.aspose.pdf.Image image1 = new com.aspose.pdf.Image();



Error: java.lang.OutOfMemoryError: Java heap space


Can you please share the source TIFF file so that we may try to reproduce the same on our end.


I’ve uploaded the file to https://imgur.com/a/Q9fDkco. However, the error is not specific to a particular tiff file. You can reproduce it with any tiff converting the file 1k, 5k, or 10k times.


I have been able to reproduce the issue on our end. A ticket with ID PDFJAVA-40715 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

1 Like

@mudassir.fayyaz do you have any updates to provide on this?



We have tested it with jdk-9. Java supports TIFF format only from Java 9 release. If you are trying to use ImageIO for TIFF into older Java version it will give you exception.

Wrapped attached code with loop and get clear memory without any leak. (25 mb only is used after each iteration and this number doesn’t grow)
It also works fine without static memory cleaner and no OOM appeared during our testing, but you can’t see the real free memory because default Garbage collector doesn’t clear memory completely after each iteration:

 for (int i = 0; i<1000; i++) {
            System.out.println("Iteration : " + i );

//customer's code here ...

public static void printMemoryStatus_hard() {
        //Forcing GC run with creating big instance.
        int[] oomArray = null;
        try {
            System.out.println("Cleaning memory...");
            oomArray = new int[Integer.MAX_VALUE - 4];
        } catch (OutOfMemoryError e) {
            //Do nothing
        } finally {
            oomArray = null;

    public static void printMemoryStatus() {

        Runtime rt = Runtime.getRuntime();
        long max = rt.maxMemory() / 1048576;
        long total = rt.totalMemory() / 1048576;
        long free = rt.freeMemory() / 1048576;
        long used = total - free;
        long realFree = max - used;
        System.out.println("** Memory status (max / used / free):\n\t" + max + "  /  " + used + "  /  " + realFree);
        System.out.println("\t" + new Date() + "\n");

        System.out.println("Active threadCounts: "+ManagementFactory.getThreadMXBean().getThreadCount());        

Maybe the problem in specific tiff loader or encoder that is used if jdk version is lower than 9. Or we need additional information about system and runtime environment to reproduce the issue.

We are not able to upgrade our java right now. Do you have another idea?


I am afraid only these details are available for now. You may upgrade for testing purpose if the issue is fixed and then share your findings.