I am using selenium with Firefox to automate some tasks on Instagram. It basically goes back and forth between user profiles and notifications page and does tasks based on what it finds.
It has one infinite loop that makes sure that the task keeps on going. I have sleep() function every few steps but the memory usage keeps increasing. I have something like this in Python:
while(True): expected_conditions() ...doTask() driver.back() expected_conditions() ...doAnotherTask() driver.forward() expected_conditions() I never close the driver because that will slow down the program by a lot as it has a lot of queries to process. Is there any way to keep the memory usage from increasing overtime without closing or quitting the driver?
EDIT: Added explicit conditions but that did not help either. I am using headless mode of Firefox.

sleep()to waits won't change anything re: mem usage. Te reason for not using sleep is because this hardcodes an interval where your script is not doing anything, in the hope the page will change state; and with the *Wait the interval is not hardcoded, but "as soon as the change happened ". In your usecase it does sound like you use thesleep()as delimiter between executions, and running in an infinite loop you don't sound like you'd care for shaving a few seconds off.