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

Client-side memory leak when re-creating Plotly elements #2640

Open
falkoschindler opened this issue Feb 29, 2024 · 4 comments
Open

Client-side memory leak when re-creating Plotly elements #2640

falkoschindler opened this issue Feb 29, 2024 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@falkoschindler
Copy link
Contributor

Description

As noticed by @eddie3ruff in #2597, there's a memory leak when re-creating many Plotly elements. The memory consumption of the browser tab (tested with Chrome) will grow until it crashes eventually:

import random
import plotly.graph_objects as go
from nicegui import ui

def update_data():
    container.clear()
    with container:
        ui.plotly(go.Figure(go.Scatter(y=[random.random() for _ in range(10)])))

container = ui.card()
ui.timer(0.1, update_data)

We already found a reproduction without NiceGUI:

<html>
  <body>
    <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    <div id="container"></div>
    <script>
      setInterval(() => {
        Plotly.react("container", [{ y: Array.from({ length: 10 }, () => Math.random()) }]);
      }, 100);
    </script>
  </body>
</html>

Is this a bug in plotly.js? How can we update or re-create plots without causing this issue?

@falkoschindler falkoschindler added bug Something isn't working help wanted Extra attention is needed labels Feb 29, 2024
@rodja
Copy link
Member

rodja commented Feb 29, 2024

I could not reproduce the issue on my Apple Silikon M3 Max. I added a title to the page to better find it in the chrome task manager <head><title>Plotly Memory Test</title></head>. Even reducing the delay of the interval to 10 ms did not raise the memory. I wanted to try if a Plotly.purge('container'); would make any difference. But it seems for me everything works as it should even without such manual management.

@falkoschindler
Copy link
Contributor Author

@rodja On my Apple M1 Max it takes about 1-2 minutes to see a significant growth. Did you wait that long?

Maybe it depends on how quickly the CPU can run the garbage collection. I did a longer test with an interval of 1 second, which uses more or less constant memory.

@rodja
Copy link
Member

rodja commented Mar 2, 2024

Maybe it depends on how quickly the CPU can run the garbage collection.

Looks like it. Even when running the 10 ms delay demo for more than 30 min, there is no recognizable increase.

@bmaranville
Copy link
Contributor

in Brave Browser on Windows 10 the plotly test HTML page above starts out using about 91 MB, but then drops to 86 MB after a minute, then after 2 minutes was using about 81 MB, so no leak here.

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

No branches or pull requests

3 participants