Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

while loop massive memory leak #7989

Closed
3 of 4 tasks
ks00x opened this issue Jan 21, 2024 · 2 comments
Closed
3 of 4 tasks

while loop massive memory leak #7989

ks00x opened this issue Jan 21, 2024 · 2 comments
Labels
status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working

Comments

@ks00x
Copy link

ks00x commented Jan 21, 2024

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • 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: #6510

Reproducible Code Example

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

@ks00x ks00x added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Jan 21, 2024
Copy link

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

@kmcgrady
Copy link
Collaborator

Hey @ks00x Thanks for the report! We do actually not remove images from our media file manager until the script finishes running, which would explain the massive memory leak being shown with the example.

As for the refresh, we are working on a concept of "partial reruns" which should make this easier to manage memory-wise. Part of the problem is how well Python garbage collects (we've seen examples of the memory increasing, but Python is not utilizing it all). Going to close cause I think we will have better solutions in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants