Skip to content

Commit

Permalink
fix: Fix HTJ2K decoder leak
Browse files Browse the repository at this point in the history
Commit 85fd193 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.
  • Loading branch information
abustany committed Jul 11, 2024
1 parent 979c403 commit e72f82a
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packages/dicomImageLoader/src/shared/decoders/decodeHTJ2K.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ export function initialize(decodeConfig?: LoaderDecodeOptions): Promise<void> {
// 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
Expand Down

0 comments on commit e72f82a

Please sign in to comment.