konvajs / react-konva

React + Canvas = Love. JavaScript library for drawing complex canvas graphics using React.
https://konvajs.github.io/docs/react/
MIT License
5.8k stars 260 forks source link

Advice for `cache` usage w.r.t memory leak #777

Closed jack-tutor closed 1 year ago

jack-tutor commented 1 year ago

Hi, I am working on a web app that frequently has images streamed to it. We render these images using react-konva - and on one set of images, we are applying a filter a la: https://konvajs.org/docs/react/Filters.html

This means that we are consistently calling .cache() though on the same useRef attached to the same KonvaImage component.

The web app has a memory leak which appears to be due to images, though not necessarily react-konva. I'm lookiing to find out:

Thanks

lavrton commented 1 year ago

Calling node.cache() should not produce any leaks. A new cache just overwrite the old one. There is no global cache, only cache per node. So if a node is destroyed, or you cleared cache manually with node.clearCache() all should be ok.

You need to run a memory profile to see what is leaking.