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

Memory leak in elastic-charts #1148

Closed
timroes opened this issue May 6, 2021 · 2 comments · Fixed by #1201
Closed

Memory leak in elastic-charts #1148

timroes opened this issue May 6, 2021 · 2 comments · Fixed by #1201
Assignees
Labels
bug Something isn't working

Comments

@timroes
Copy link

timroes commented May 6, 2021

Elastic charts currently (in the version on Kibana master 29.1.0) has a memory leak in it's caching layer, that keeps a huge amount of detached DOM nodes around. We're using re-reselect in some place, that by default uses a FlatObjectCache to cache selectors. That will lead to those selectors simply be "cached forever". We use this via the getSeriesSpecsSelector funtion and our state that we cache actually has references to DOM nodes around, that might later be detached, but then kept alive by this cache, preventing the browser from cleaning up the DOM node (and a potential large DOM tree attached to them).

We should ideally make sure that the state that we cache there, does not keep strong references to DOM elements around, that will prevent them from being garbage collected. Alternatively (or better in addition) we can tell re-reselect what cache object it should use (https://github.com/toomuchdesign/re-reselect#cacheobject) and might want to consider one that at least limits the cache size.

This problem is causing problems (high memory consumption, huge detached DOM node count) in placed like Discover where we exchange the chart, e.g. when switching index patterns. If you continue switching index patterns you will see the amount of DOM nodes and JS heap size growing and never be reduced, due to elastic-charts keeping them alive via this cache.

@timroes timroes added the bug Something isn't working label May 6, 2021
@nickofthyme
Copy link
Collaborator

Thanks for the detailed description Tim, we'll get on it right away.

@nickofthyme
Copy link
Collaborator

More findings:

I am seeing a retained reference the the .echTooltip element which is a child of the createPortal call. Could be related to facebook/react#18790, also could be a dev-only memory issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants