How to clear memory after closing the app?!

I have an app running on streamlit share. I understand my model is heavy and it’s downloaded into memory once we hit run inside the app and I think it’s not leaving the memory even when we close the app. Due to this, I’m facing the above error and I have to reboot the app every time.

Is there any code to automatically clear the memory each time we close the app?!