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.

Suspected memory leak

See original GitHub issue

My server uses chartjs-node-canvas to generate many charts into a pdf. I ran the chrome heap profiler and noticed that each time I generate the report, I get a significant amount of chart related records with high retained sizes. Below are the screenshots:

Screen Shot 2019-11-21 at 12 17 39 AM Screen Shot 2019-11-21 at 12 19 47 AM

Code usage:

rangeLine(min, max, value).then(chart => {
  ...
});

const rangeLine = (min, max, val) => {
  const canvasRenderService = new CanvasRenderService(170, 30);
  return canvasRenderService.renderToBuffer({
    type: "line",
    data: {
      datasets: [
        {
          pointBackgroundColor: "white",
          borderColor: "black",
          data: [
            {
              x: min,
              y: 0
            },
            {
              x: mid,
              y: 0
            },
            {
              x: max,
              y: 0
            }
          ]
        },
        {
          pointBackgroundColor: 'blue',
          pointRadius: 10,
          pointStyle: "rectRot",
          data: [
            {
              x: val,
              y: 0
            }
          ]
        }
      ]
    }
  });
};

Version: v2.4.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SeanSobeycommented, Jan 26, 2020

Hi seth.

freshRequire is needed to isolate canvas instances since actions in the library’s API mutate global state inside, canvas width and height for example. This way each CanvasRenderService encapsulates that state for you, at the cost of a bit of complexity with things like chart plugins, fonts etc.

The code you mention does actually appear like a bug, but could possibly be done that way for some reason. I will investigate more tomorrow to confirm but yeah looking at it I can’t think of why there would be separate instances for font and the canvas.

0reactions
seth2810commented, Jan 29, 2020

Thank you, Sean.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java Memory Leaks: Solutions, Tools, Tutorials & More - Stackify
We put together this guide to help you understand how, why, and where Java memory leaks happen – and what you can do...
Read more >
Hunting Java Memory Leaks - Toptal
A memory leak occurs when object references that are no longer needed are unnecessarily maintained. These leaks are bad. For one, they put...
Read more >
Java Memory Leak Detection: Causes & Tools to Avoid Them
The memory leak is a situation where an object or objects are no longer used, but at the same time, they can't be...
Read more >
How to Fix A Windows Memory Leak - Lifewire
The steps below show how to view your system's memory usage in Windows 10, 8, and 7. Press Windows key+R, enter "resmon," then...
Read more >
Creating a Memory Leak Diagnosis report - IBM
In the Memory Leak Diagnosis report each row in the Suspected Memory Leaks table represents an allocation pattern for which memory allocation data...
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