Skip to content

Memory leak in SharedClientStateServer #511

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

Closed
rmorshea opened this issue Sep 10, 2021 · 2 comments · Fixed by #514
Closed

Memory leak in SharedClientStateServer #511

rmorshea opened this issue Sep 10, 2021 · 2 comments · Fixed by #514

Comments

@rmorshea
Copy link
Collaborator

I've stumbled upon another memory leak, this time in SharedClientStateServer. Try this:

import idom
from idom.server.sanic import SharedClientStateServer

@idom.component
def SomeComponent():
    ticks, set_ticks = idom.hooks.use_state(0)
    set_ticks(ticks + 1)
    return idom.html.div()

server = SharedClientStateServer(SomeComponent)
server.run("127.0.0.1", 8000)

If you open the browser window, and then exit it, the process memory runs amok. Again, this is primarily driven by frequent state changes - if you use my original example and reduce the ticker interval, it does not occur. However, if you create a lot of elements dependent on that state (e.g. 1000 buttons but a 0.1s timer), it happens again. The issue I have in practice is that I believe the leak still occurs in a normal application if you exit the browser window at an inconvenient time - and this is the closest example I've been able to come up with.

Originally posted by @mx781 in #509 (reply in thread)

@rmorshea rmorshea added the bug label Sep 10, 2021
@rmorshea
Copy link
Collaborator Author

rmorshea commented Sep 10, 2021

Assuming that the leaks in fact occur because the client disconnects at an inconvenient time, the solution is probably to add some cleanup steps to the shared view dispatcher. From what I remember, no such cleanup happens at the moment.

@rmorshea
Copy link
Collaborator Author

Yup, it looks like there's a step to add an update queue for a new client, but not a step to remove it after the client disconnects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant