Setting img.src to dataUrl Leaks Memory

后端 未结 5 900
萌比男神i
萌比男神i 2021-01-02 04:16

Below I\'ve created a simple test case that shows that when an img tag\'s src is set to different dataUrls, it leaks memory. It looks like the image data is never unloaded a

5条回答
  •  太阳男子
    2021-01-02 05:10

    Some solutions not mentioned in the other answers:

    For browser

    jpeg-js

    Similar to jpgjs mentioned by @PaulMilham, but with additional features and a nicer API (imo).

    For NodeJS/Electron

    sharp

    General purpose image-processing library for NodeJS, with functionality to both read and write jpeg, png, etc. images (as files, or just in memory).

    Since my program is in Electron, I ended up using sharp, as jpeg-js mentioned it as a more performant alternative (due to its core being written in native code).

提交回复
热议问题