Memory leak while loading and saving PSD files


We are having a memory leakage problem. Our application uses Aspose.PSD lib to load a PSD file and update some layers and save that file as JPEG image. Memory usage starts to increase with the use of this functionality.

We made a test application that proves that problem exists (AppLink).
Code sample:

static void Execute(int index)
    string psdName = $"AsposeTestApp.testPsd{index}.psd";
    Console.WriteLine("Loading {0}", psdName);

    using MemoryStream outputStream = new();
    using Stream psdStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(psdName)
        ?? throw new Exception("Resource not found!");

    using PsdImage psd = (PsdImage)Image.Load(psdStream, new PsdLoadOptions { LoadEffectsResource = true });

    psd.Save(outputStream, new JpegOptions() { Quality = 100 });

Calling this method multiple times causes to memory start growing. The test scenario uses 3 different psd files in the for loop (files are also provided in testApp).

Memory diagram:
image.png (53.2 KB)

While profiling we notice that there is some static dictionary (probably some cache) holding reference to the objects (see picture below).

image.png (33.2 KB)

This problem is causing OutOfMemoryException in our application and we don’t know how to avoid it.

@mydesignsio thank you for your report and investigation. I created the issue with High priority: PSDNET-1266. Memory leak on the processing of specific files. When it will be fixed, you’ll get notification. We planned to fix in it Aspose.PSD 22.10.

@mydesignsio could you please check if the memory leak was fixed for you. This update was delivered in Aspose.PSD 22.10

@DmitriySorokin It’s fixed, memory usage is constant.

1 Like