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.

Line Chart has memory leak

See original GitHub issue

I ran into the same problem as other users where the line chart’s memory was not being released after calling destroy(). I took the sample line chart code to illustrate this. Simply call LoopIt() and watch the memory usage increase.

<!doctype html>

<html> <head> <title>Line Chart</title> <script src="../Chart.js"></script> </head> <body> <div style="width:30%"> <div> <canvas id="canvas" height="450" width="600"></canvas> </div> </div>
<script>
    var randomScalingFactor = function(){ return 5};
    var lineChartData = {
        labels : ["January","February","March","April","May","June","July"],
        datasets : [
            {
                label: "My First dataset",
                fillColor : "rgba(220,220,220,0.2)",
                strokeColor : "rgba(220,220,220,1)",
                pointColor : "rgba(220,220,220,1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(220,220,220,1)",
                data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
            },
            {
                label: "My Second dataset",
                fillColor : "rgba(151,187,205,0.2)",
                strokeColor : "rgba(151,187,205,1)",
                pointColor : "rgba(151,187,205,1)",
                pointStrokeColor : "#fff",
                pointHighlightFill : "#fff",
                pointHighlightStroke : "rgba(151,187,205,1)",
                data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
            }
        ]

    }

function Reload(){
    var ctx = document.getElementById("canvas").getContext("2d");
    window.myLine = new Chart(ctx).Line(lineChartData, {
        responsive: true
    });
}

function LoopIt(){
    if(!window.myLine)
        Reload();


    for(var i = 0; i < 100; i++)
    {  
        myLine.destroy();
        Reload();
    }
}


</script>
</body>
</html>

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Legendscommented, Dec 29, 2016

No I didn’t, works perfect now!

0reactions
etimbergcommented, Dec 29, 2016

@Legends did you call destroy() on that chart?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak in Line Chart data · Issue #2772 - GitHub
When popping screen back or selecting another tab from the UITabBarController, there will be a memory leak that'll occur from the chart.
Read more >
Line chart memory leak in a one page application - RGraph
Hello RGraph team, I actually using RGraph.line to show a curve in one of pages in a web app. And every thing is...
Read more >
Memory leak in google line charts - Stack Overflow
In the code above I was trying to splice/pop out the data in the array, but seems like thats wont do anything. The...
Read more >
Real-time line chart & memory leak issue | DevExpress Support
A memory leak occurred while using a real-time linear chart. The source code used the source code of the 17.2 demo center. The...
Read more >
I have a question about memory leak - Highcharts
Hello, I'm implementing a real-time chart with highchart v7 , javascript and chrome (newest). My chart updates the data received from the ...
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