Weird memory usage behavior

Hey @hertzmann -

Without seeing the entire script, it’s hard to know what’s going on here (and possibly hard to know even with the full context!).

My hunch is that this is either a bug in PyTorch (that GPU memory is almost surely being allocated by non-Python FFI code within PyTorch), or an error in PyTorch usage. Since Streamlit apps are “long-lived” in the sense that the Python interpreter does not shut down between app runs, they can surface memory leaks that wouldn’t otherwise be noticeable in a comparable script that runs to completion and then exits completely.

st.image - and most other st.foo functions - do create some data that’s persisted across runs, but it’s specifically serialized protobuf objects that by definition can’t hold pointers to PyTorch objects or anything else, so I’m fairly sure there’s nothing inside st.image that’s causing this - but never say never when it comes to memory leaks :slight_smile:

It would be useful to know: Do you still see the behavior if you remove the call to st.image? If not, I don’t think this is anything to do with Streamlit. (But if so, we’d love to know!)