question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use text inside svg will cause memory leak

See original GitHub issue

In 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shasharomancommented, Aug 6, 2018

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.

0reactions
lovellcommented, Aug 4, 2018

I’m unable to reproduce this with the latest version of sharp on Linux using the “simplified code” of the first comment.

100 { rss: 47820800,
  heapTotal: 8208384,
  heapUsed: 5804256,
  external: 16960 }
500 { rss: 48328704,
  heapTotal: 8732672,
  heapUsed: 6690656,
  external: 36384 }
1000 { rss: 47693824,
  heapTotal: 8732672,
  heapUsed: 5918232,
  external: 25344 }

Which platform and versions are you using?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found