Closed astomnbkn closed 2 years ago
Hi @astomnbkn -
Try using st.experimental_singleton
and see if that helps. Theoretically, that means a single copy of the data will only ever be present, whereas memo can place multiple copies in memory.
Best, Randy
Hello @randyzwitch , Thanks for commenting.
I did not look closely enough and did not recognize st.experimental_memo was used in that code. I'm checking the cases of using no caching mechanism and using session_state. both is acting the same and after some hours streamlit server uses more memory. Probably the same for web browser.
The issue is memory consumption when rerun is done many times. My understanding is that when app is rerun, anything from previous run is not needed anymore and should be reclaimed at some later point in time, as long as it is not shared among reruns, like experimental_singleton or session_state.
I would like to do some more testing and get back here when I have something.
Hi @astomnbkn , closing this issue since it seems randy solved your problem. If you feel like there is a need to reopen it, please feel free to.
Summary
I want my app keep rerun-ing periodically forever but streamlit server and web browser both keeps using more memory as they keep running repeatedly. I use a component to create timer on client side and let it do streamlit.setComponentValue(v) to kick rerun on server. streamlit 1.8.1 to 1.10.0 seems to have the same issue. Setting dataFrameSerialization "arrow" or "legacy", the same issue. I have no clue if this is related to using altair chart or not.
Am I missing something to implement automatic rerun from script so that it can rerun periodically?
Steps to reproduce
Code snippet: This is sample code using altair chart from streamlit.io web site, modified to use functions to avoid global variables, plus a small code to do rerun. As a demo here streamlit-autorefresh component is used. I have my custom component which uses setTimeout() but the same issue occurs.
Expected behavior:
App keeps running periodically without keep consuming more memory.
Actual behavior:
App keeps consuming memory. And after sometime the performance of the app degrades and it takes longer time to plot the chart.
Is this a regression?
Probably. I used to use streamlit 0.7x and ReportThread hack on app python script to do rerunning. As I upgraded streamlit to recent versions, that hack is not usable. I switched to use timer on client side.
Debug info
Additional information
To compare, if I use experimental_rerun() within app by code like below,
after a while app generates exception RecursionError like following. I do not know if this symptom relates to the issue of rerun.
Thank you.