[BUG] Imaging API memory leak when reading pixel data

,

Hi team,

I’m developing a UXP plugin for live updating Blender textures from Photoshop. For this I need to frequently read the image pixel data. Everything was working exceptionally well until I noticed that the plugin is leaking huge amounts of memory. I spent half a day debugging this and tried everything I could think of. Now I’m 99% sure that this little code snippet is leaking all of the pixel data:

async function memoryLeakTest() {
    let pixels = await modalWrapper(async () => await imaging.getPixels({}), "Reading image pixel data");
    const { imageData, sourceBounds, level } = pixels;
    const pixelData = await imageData.getData();
    imageData.dispose();
}

The function reads all pixel data from the active document and does nothing with it. When commenting out the call to imageData.getData() no memory leak happens.

I created a simple test plugin which would just call this function when a button is pressed. After hitting the button the Photoshop process memory increases roughly by the size of the pixelData buffer. This happens every time I press the button until the OS runs out of memory. You can see it very clearly when you use a large 5k image for testing.

I tested this on Windows and MacOS using Photoshop version 26.5.

You can also use the Imaging API example plugin (imaging-test) to reproduce the memory leaks.

Can you please check this on your end? I’m running out of options. In this state the plugin cannot be given to users.

Cheers.

1 Like

try: pixels.imageData.dispose();

This sounds more like the use case for Generator Plugins/Image Assets.

The Imaging API is not intended as an export mechanism.

Thanks for your responses.

I simplified my example above to make it more obvious that dispose() is correctly called. As I said these three lines are leaking what appears to be all of the memory allocated for the pixels. Even though dispose() is called. This can easily be reproduced on Mac and Windows.

@samgannaway Please don’t worry about what I’m doing with the pixel data later. I should not have mentioned the Blender thing. The memory leak happens for everybody who calls imageData.getData() no matter the use case.

async function memoryLeakTest() {
    const pixels = await modalWrapper(async () => await imaging.getPixels({}), "Reading image pixel data");
    const pixelData = await pixels.imageData.getData();
    pixels.imageData.dispose();
}

I tried to reproduce the issue on the 2024 version of Photoshop and everything work fine there. So it appears to be a regression.
The memory leak is reproducible in PS 2025 version 26.5.0 but not reproducible in PS 2024 25.12.2 (PS 2024).

Memory leaks are just one of Photoshop’s features. They are all over the place. It is one of the worst maintained applications around, maybe second only to those maintained by Autodesk.

I don’t mind a small memory leak here and there. But leaking a potentially huge buffer of uncompressed image data is a big deal. Images these days are very high resolution and a plugin which processes pixel data can easily leak 100 MB of memory in a single invocation.