Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart instances persist in memory after destroy #533

Closed
Viceriel opened this issue Jun 1, 2021 · 3 comments · Fixed by #541
Closed

Chart instances persist in memory after destroy #533

Viceriel opened this issue Jun 1, 2021 · 3 comments · Fixed by #541
Labels

Comments

@Viceriel
Copy link

Viceriel commented Jun 1, 2021

Hello, I recently switched Chart.js from v2.x to 3.x. I also use the chartjs-plugin-zoom 1.0.1. My situation is this I have SPA with some tabs, on one tab are the charts, between them line chart and for this one I use the zoom plugin, because data are usually huge.

When I transit from page with charts to another, this is called for cleaning:

if (this._chart)
{
this._chart.options.onClick = null;
//desperate attempt to save situation
this._chart.options.plugins = null;
this._chart.clear();
this._chart.destroy();
}

I expected that destroy do everything necessary from memory perspective. For version 2 it is working, but here I observe strange behavior. When I switch from chart page to another and inspect memory I saw LineController(object asociated with chart.js) between objects. When I switch back to chart page and then again to another memory consumtion raise and count of LineController too. Raising instances

What i find out is this, when I comment the zoom plugin from options everything is working again, no more raising LineControll instances no visible memory consumption raise between pages switching. But this plugin is necessary for me, so commenting out is not good option. I tried manually set plugins for chart to null:

this._chart.options.plugins = null;
But this not solve the memory problem. Has anybody face such condition? I also posted question to with code snippets so

@kurkle
Copy link
Member

kurkle commented Jun 1, 2021

Are you possibly using any polyfills?

@Viceriel
Copy link
Author

Viceriel commented Jun 1, 2021

At least I'm not aware of any polyfills. When I find moment to take a breath I try to extract minimal example to flems(but not sure, how such platform allows to inspect memory, so maybe minimal html like samples is more appropriate?).

@Viceriel
Copy link
Author

Viceriel commented Jun 2, 2021

Hello. I tried extract minimal example. So I not observe same behavior(no more LineController). On the other hand seems like everything else is same. Memory consumption raises despite destroy called and only if I use plugin zoom. It looks like this, first sample is desperate toggling between pages after loading the site. Second sample is desperate toggling between pages after first one.

desperaterun

If there will be interest for this behavior, I can provide minimal html for inspection.

Maybe for comparison I add the desperate toggling without zoom plugin.
desperatewithoutzoom

@kurkle kurkle added the bug label Jun 7, 2021
@kurkle kurkle linked a pull request Jun 8, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants