Use text inside svg will cause memory leak
See original GitHub issueIn a scene, I encountered this problem when I used SVG to synthesize text onto an image.
This is a simplified code:
const sharp = require('sharp');
let count = 0;
setInterval(() => {
if (++count % 100 === 0) {
console.log(count, process.memoryUsage());
}
sharp(Buffer.from(`
<svg>
<text>example</text>
</svg>
`)).toBuffer();
}, 100);
After 500, 1000, 2000 times:
500 { rss: 343126016,
heapTotal: 9256960,
heapUsed: 7043760,
external: 44416 }
1000 { rss: 641712128,
heapTotal: 11354112,
heapUsed: 8856440,
external: 95232 }
2000 { rss: 1231851520,
heapTotal: 12402688,
heapUsed: 10316248,
external: 125248 }
I guess the underlying code is causing this problem, but I’m not sure, so give you a feedback.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Memory leak in SVG Text component in React Native macOS ...
When iterating over an array and mapping values into a <SVGText> component, the application frozens and memory usage goes up-high (>4 gb).
Read more >583471 - Memory leak with moving SVG text and blur filter
This doesn't happen if SVG text isn't moving continuously. Seems like Chrome continuously keeps caching blurred SVG and doesn't delete it?
Read more >memory leak/growth inserting new text - Inkscape - GitLab
With preferences not reset, I was using Spectral (typeface) and creating some text (under 20 objects). Memory grew from 70 MB to 600...
Read more >376414 - Plug SVG text container element memory leak
nsSVGTextContainerFrame is doing CallQI on mContent to get an interface to the element for Get{X,Y,Dx,Dy}, but never dropped the reference added by the...
Read more >Changelog for librsvg 2.42.0 - ABI laboratory
Version 2.42.0 - Fix a memory leak in rsvg_handle_new_from_file() (Lovell Fuller). ... Cargo is now verbose as well if you use "make V=1"....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I made a big mistake because my production environment is linux, and after a failure I used my own OS X (10.11.6) to locate and debug, and then guessed that using svg+text caused a memory leak.
After reading your last reply, I continued to run “simplified code” on OS X. This time I ran 8000 times and the RSS size was about 4.8G, but this may be because my machine’s available memory is too large.
After that I went to the linux environment to run this code, the RSS size is always at 30M-40M, which forced me to think about the whole problem. I then used a complete local environment to test my application, making sure it should be an RSS issue. The last application crash was an exception caused by a shortage of system memory.
After confirming that it is not a memory leak, I should focus on how to optimize RSS. I think the OS X memory leak probability is low and will not be used as a production environment, so this issue should be closed. If you are interested, you can also run “Simplified Code” in the OS X environment.
Thank you very much for providing such a good tool library.
I’m unable to reproduce this with the latest version of sharp on Linux using the “simplified code” of the first comment.
Which platform and versions are you using?