Streamlit cache uses too much ram

Hi @CharlesFr, just wanted to add that there is a memory leak that will be fixed in version 1.32 of Streamlit, and in the meantime, you can use this wheel file.

Our team has a few other suggestions for reducing memory usage in this thread (I’ll paste below).

To lower the memory usage, there are two quick things you could try:

  1. Use this wheel file which fixes a memory leak. This leak was fixed last week and will be released with 1.32.
  2. Deactivate the backend storage of forward messages in config.toml via (requires at least 1.30):
[global] 
storeCachedForwardMessagesInMemory = false

This is a bit of an old artifact that most likely doesn’t have any use. And its a bit of a problem if there is a spike of user sessions.

These two aspects might help with the issue, but there are other memory inefficiencies we are currently investigating. To give you more specific help, it would be great if you can tell us which of the following features your app is using:
st.file_uploader , st.image , st.video , st.audio , st.pyplot, st.download_button , long running sessions using st.rerun , large dataframes/charts, or any of the caching decorators?

For my understanding, what does Streamlit use ephemeral/disc storage for? Are cached and pickled objected stored on disc or in memory?

I think everything in a normal Streamlit setup is stored in memory. However, you can configure certain aspects to store on disk (e.g. via st.cache_data(persist="disk")). But you are probably not doing that, or?

2 Likes