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.

ChartsJS: Memory leak after ajax updates

See original GitHub issue

Describe the defect On our page we have multiple p:barChart components that are updated with ajax when there is new data available. After a while an out of memory error occurs in the browser. Some investigation showed that the JavaScript object Chart of the ChartJS library keeps all the old chart instances and after an update also has the new ones. So this probably also affects other types of charts that are drawn using ChartJS.

Environment:

  • PF Version: 10.0.0
  • JSF + version: Mojarra 2.3.14
  • Affected browsers: ALL

To Reproduce Steps to reproduce the behavior:

  1. Have a p:barChart on your page, you can just use the showcase for this.
  2. Update it with ajax, e.g. add the following button and click it a few times:
<p:commandButton value="update" update="@(.ui-chart)" oncomplete="console.log(Chart.instances)"/>
  1. Check the browser’s JavaScript console.
  2. See the error, after each update, the number of instances grows and grows.

Expected behavior No longer used chart instances should not remain in memory. According to the ChartJS documentation, probably the destroy() method should be called for all no longer used chart instances, see: https://www.chartjs.org/docs/latest/developers/api.html#destroy

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jthalmaicommented, Jun 1, 2021

Thanks, this works.

1reaction
jthalmaicommented, May 7, 2021

The MonkeyPatch works for us. Only the current instance is kept.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Line chart causes browser memory leak · Issue #462 - GitHub
I am updating a Line chart using ajax. It works great, however the browser memory ramps up to where it causes the browser...
Read more >
Memory leak using google charts with ajax - Stack Overflow
I'm fairly new to javascript and I'm having trouble finding a memory leak in some code which updates a google chart each second...
Read more >
4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
In this article we will explore common types of memory leaks in client-side JavaScript code. We will also learn how to use the...
Read more >
Memory Leak | CanvasJS Charts
1) In this example when you click the 'run' button and then 'reload' and 'run' multiple times the browser memory increases and never...
Read more >
jqPlot browser memory leak on chart update - PrimeFaces forum
Hi, Im working with primeface 3.1, when I update a <p:barChart/> from ajax event on <p:selctOneRadio/> , the browser (IE8, Chrome or Mozilla ......
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