seikichi / tiff.js

tiff.js is a port of LibTIFF by compiling the LibTIFF C code with Emscripten.
Other
387 stars 98 forks source link

Memory leak #70

Open Kroppeb opened 1 year ago

Kroppeb commented 1 year ago

I have the following code:

// Create a new instance of the FileReader
const reader = new FileReader();

// Use the FileReader to read the blob as an ArrayBuffer
reader.readAsArrayBuffer(file);

const arrayBuffer: ArrayBuffer = await new Promise(resolve => {
    reader.onload = () => resolve(reader.result as ArrayBuffer)
})

const tiff = new Tiff({buffer: arrayBuffer});
const canvas: HTMLCanvasElement = tiff.toCanvas()

const convertedBlob: Blob = await new Promise(resolve => canvas.toBlob(result => resolve(result!), 'image/png'));

return URL.createObjectURL(convertedBlob);

The created URL's get revoked afterwards, yet there still seems to be a memory leak of some sorts. It also seem that once the memory leak hits a critical point, the library fails to read the data properly, and each subsequent image passed through causes an error. Yet those still keep increasing the memory footprint of the application.

I'm running this in FireFox btw, idk if that matters

Kroppeb commented 1 year ago

It seems I should call tiff.close(), that seems to reduce the memory usage quite a bit. It seems there are still buffers being retained with the following gc path. Not quite sure yet where these are coming from.

BODhaha commented 1 year ago

has same issue