Tomasz
February 26, 2025, 11:34pm
1
Streamlit 1.42.2, python3.10 (running in python:3.10-slim container)
I have a simple code like below:
import streamlit as st
import numpy as np
import time
while True:
frame = np.random.randint(0, 256, (1920, 1080, 3), dtype=np.uint8)
st.image(frame, channels="RGB")
time.sleep(0.1)
The above code is just an example, simulating previewing a video cap, but still - its enough to see the problem.
I’m running top to see resources usage and unfortunately I see a memory leak.
Do You have any idea how to fix it?
Goyo
February 28, 2025, 10:16am
2
Take a look at this comment in the issue tracker:
opened 11:23AM - 21 Jan 24 UTC
closed 10:11PM - 22 Jan 24 UTC
type:bug
### Checklist
- [X] I have searched the [existing issues](https://github.com/st… reamlit/streamlit/issues) for similar issues.
- [X] I added a very descriptive title to this issue.
- [X] I have provided sufficient information below to help reproduce this issue.
### Summary
The code below is the simplest I could come up with to demonstrate it. With the image shown the memory usage increases rapidly into the GB regime. However, even without the video shown, the memory increases because of the np.random call. This suggests that the problem is not st.image specific. Restarting the script causes the memory to become free!
streamlit version 1.30.0.
In my actual application I added an st.rerun() call every 10min to reduce the memory usage, but there is still a slower increase in memory consumption caused by something else.
There is an earlier thread that was closed: https://github.com/streamlit/streamlit/issues/6510
### Reproducible Code Example
```Python
import streamlit as st
import numpy as np
st.button('restart')
show = st.checkbox('show video',value=True)
vid = st.empty()
while True :
im = np.random.random((500,500))
if show :
vid.image(im)
```
### Steps To Reproduce
_No response_
### Expected Behavior
leveling off of memory usage
### Current Behavior
linear increase of memory usage with time
### Is this a regression?
- [ ] Yes, this used to work in a previous version.
### Debug info
- Streamlit version:1.30.0
- Python version:3.11.5
- Operating System:win10
- Browser:brave
### Additional Information
_No response_
Read also the other comments and the links, they can provide workarounds.