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

Free Support Forum - aspose.com

About OutOfMemory Exception

While editing a psd file and save it into another file, after I use Image.setLayers function or Image.addLayer function, the memory used by PsdImage will not release even after I call Image.dispose(). The memory used will keep increasing while I repeat editing. How to free the memory occupied by PsdImage?

@Midas1990

Can you please share a working sample code reproducing the issue along with source file and also the memory profile images. We will try to investigate that further on our end on the basis of that.

 PsdImage loadImage = (PsdImage) Image.load(sourcePSDPath);

    List<Layer> layerList = new ArrayList<>();
    List<LayerGroup> groupList = groupLayers(loadImage.getLayers());

    PsdImage image = new PsdImage(loadImage);
    for (Layer layer : loadImage.getLayers()) {
        image.addLayer(layer);
    }
    image.save(targetPSDPath, new PsdOptions());

    image.dispose();

    loadImage.dispose();

Run the code above for a few times, memory is keep increasing.

@Midas1990

Can you please share the source file as well along with memory profile image that we may use on our end to investigate.

you can test with any psd file.

@Midas1990

I request you to please provide the memory profile image describing the memory not being released and increasing further in iterations.

before run the code before load and save.png
run the code 1 cycle 1st cycle.png (35.4 KB)
run the code 5 cycles 5 cycles.png (28.4 KB)
run the code 10 cycles10 cycles.png (25.8 KB)
run the code 20 cycles20 cycles.png (23.6 KB)
(32.1 KB)
I found if I remove line image.save(targetPSDPath, new PsdOptions()); the memory is not increasing.
My dependency is
com.aspose
aspose-psd
21.7
javadoc

    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-psd</artifactId>
        <version>21.7</version>
        <classifier>jdk16</classifier>
    </dependency>

@Midas1990

I have created a ticket with ID PSDJAVA-368 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be addressed.

thank you for your kindly support