#12073·pixijs

Transcoder memory leak when using KTX2

Author: venteralex1Created Jun 3, 2026Updated Aug 3, 2026
Labelstype: performancepriority: highstatus: needs triagescope: rendering

PixiJS version

8.18.1

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-buggabup?file=src%2Fmain.js

Steps to reproduce

  1. Have a fairly large texture in ktx2 format
  2. Load the image using Assets with ktx2 parser (this leads to transcoding with a worker)
  3. Unload the image from Assets
  4. Repeat
for (let i = 0; i < 10_000; i++) {
    console.log(`Iteration ${i}`);
    await Assets.load({
      src: `./image.ktx2`,
      parser: 'ktx2',
    });
    await Assets.unload('./image.ktx2');
}

What is expected?

This cycle should be able to continue for an infinite amount of images.

What is actually happening?

The transcoder creates a worker for it's task the first time it is used, then proceeds to use this worker in subsequent tasks.

\lib\compressed-textures\ktx2\worker\loadKTX2onWorker.js:
...
"use strict";
let ktxWorker;
...
function getKTX2Worker(supportedTextures) {
  if (!ktxWorker) {
    ktxWorker = new ktx_worker.default().worker;
    ...
  }
  return ktxWorker;
}
...

It is not possible to access, clear or otherwise modify the memory management of this worker, which leads to a memory leak after some iterations (~1500 on my machine):

ERROR: Failed to transcode: Out of memory.
main.js:21 Uncaught (in promise) Error: [Loader.load] Failed to load https://vitejsvitebuggabup-dsu1--5173--bd880c29.local-credentialless.webcontainer.io/image.ktx2.
Error: Unable to transcode basis texture.
    at load (54f8db0a-1f13-4a39-81c0-435cfe321b09:190:17)
    at async Object.load (54f8db0a-1f13-4a39-81c0-435cfe321b09:221:34)
    at async self.onmessage (54f8db0a-1f13-4a39-81c0-435cfe321b09:237:26)

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (22) x64 Intel(R) Core(TM) Ultra 7 165H
    Memory: 10.69 GB / 31.46 GB
Browsers:
    Chrome: 148.0.7778.216
    Edge: Chromium (147.0.3912.72)

Any additional comments?

Hello! Unfortunately I ran into this problem as I was trying to optimize images for my video-player-like application. It involves switching huge background images fairly quickly, which is why I'd like to leverage the .ktx2 format.

However, as a comment in previous issue #11768 states, the worker is not exposed. We should be able to clear or terminate it somehow.

My suggestion would be either to expose the worker, or use the Assets.loaders.reset() (https://pixijs.download/release/docs/assets.Loader.html#reset) function to destroy it. This function doesn't seem to have a purpose yet anyways.