Hi
I have created a Streamlit app that I have been running both locally on my Mac Book Pro and on a Linux server with Ubuntu 20.04.1 LTS. I noticed a clear difference that the memory of the Ubuntu server is increasing continuously over time when used while on my Mac it is increasing when used but decreases after a while. The only difference is that the Ubuntu version uses a GPU instead of the CPU when running. Can it be the issue?
Unfortunately, I cannot share the source code, but I use Detectron2 that is built on pytorch for object detection.
EDIT: I just realised that I should try to se the behaviour with using only CPU on the Linux server also to see if that is the problem, but the problem remains even when the Linux server also only uses CPU. I use Streamlit 0.71.0.
Is there a chance that the memory leak comes from Detectron2, or at least its usage inside Streamlit?
One way I see to check if Streamlit is the one to blame would be to create a small Python script which does the following:
At the beginning of your script, prepare multiple predictions to do, as many as you’ve done in Streamlit to trigger the memory leak
Run them in a for loop
Add a long time.sleep in the end, and check if you have any memory leak
The goal here is to reproduce Streamlit’s behavior, that is, run multiple predictions using one python process.
If you notice a memory leak with such python script, maybe there are some resources not freed. Maybe some GitHub issues report memory leaks for Detectron2.
After ruling out that the problem was due to Detectron 2, I have found a reason for the huge memory usage. Because of previous warnings that I mutated cached data I made a deep copy of my data (including images) as was recommending in the warning. Every time the script is executed, a new copy of the cached data was created. When I removed the deep coping, the huge memory usage stopped. However, I still wonder why the deep copies are kept in memory after each execution since there is no reference kept for it in the code I would assume?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.