From e72f82a2665a1d472ccea8a757f44d65a59516ba Mon Sep 17 00:00:00 2001 From: Adrien Bustany Date: Thu, 11 Jul 2024 12:01:54 +0200 Subject: [PATCH] fix: Fix HTJ2K decoder leak Commit 85fd19396762f54c6806fdbebf0235139a67629a changed decodeHTJ2K.js to allocate a new HTJ2KDecoder with each call to decodeAsync. The old decoders somehow stay alive, and are not cleaned from the WASM memory. Each new HTJ2KDecoder allocates in turns buffers for the encoded and decoded pixel data while decoding. The change to allocate a new decoder per frame argued that reusing the old decoder is "much slower", but I could not reproduce any slowdowns either in the browser or on Node. This commit therefore reverts the change, so that each call to decodeAsync reuses the same decoder instance. --- packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts b/packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts index 3616e4e16..1e659dbda 100644 --- a/packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts +++ b/packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts @@ -57,8 +57,7 @@ export function initialize(decodeConfig?: LoaderDecodeOptions): Promise { // https://github.com/chafey/openjpegjs/blob/master/test/browser/index.html async function decodeAsync(compressedImageFrame: ByteArray, imageInfo) { await initialize(); - // const decoder = local.decoder; // This is much slower for some reason - const decoder = new local.codec.HTJ2KDecoder(); + const decoder = local.decoder; // get pointer to the source/encoded bit stream buffer in WASM memory // that can hold the encoded bitstream