Dash memory leak - Close tab or window

Hi everyone,

Thanks to the whole forum, I created an application that runs heavy simulations and shares graphics.
I dockerized the application, and run the container.

The container memory usage increases for each new tab of my application. However, if I close the tab, the memory usage does not decrease. I feel like the page keeps running serverside instead of closing.

I have not found any resources about this issue. Does anyone know how to handle the tab/window closing event and how to cut the process?

I tried changing the server behaviour by setting server.permanent_session_lifetime and session. permanent. It does not seem to have any effect.


1 Like

Have you been able to solve this? I am getting the same issue

This library crashes my code :frowning:

I did find out what the issue was though, I was calling app.run_server(debug=True) in my container, changing debug to False fixed the buildup


What does the unload component do in this case?

1 Like

any update on this?

debug=False did not alleviate my problem.

Bumping because I just asked about this exact issue.

Experimenting with the debug=False and will report back if it solves it.

Make sure that you arent accumulating global variables and not printing to the python console during runtime as both of these things will lead to memory leaks.

Does that count also for object instances that are defined in the global scope?

As long as it stays in memory of the app, this would continue to expand. As far as I understand it.

Yup, it’s right.
But as for my case, it has a downside. Let’s say I have 3 global variables:

  • A class instance for some static methods and get my data tables.
  • A 1° table of data that is store in Cloud.
  • A 2° table of data thtat is also store in Cloud.

I decided to get rid of those global variables and instantiate them inside the callbacks. This prevented the memory leak when closing the app that I had previously. BUT this came with some slowness in the response time of my app, since it had to go to the cloud storage and retrieve the tables in each callback. So that’s a big no no, because let’s remember, user experience is priority.

So… Now I came with some crazy idea (I haven’t look through Dash documentation yet):

Is there any way for my Dash code to detect when the user closes the window, in order to trigger a del() of those variables?

Yes, @FrancoCapeletti, you can know when a user closes a window by listening to the beforeunload even on the client. You can check the forums for how to do so.

But, you could also check out ServerSide output for caching the info as well.