Possible problem with memory leak
During each focus, there seems to be a new object added to the app.layout._stack
member. Since we are focusing 1/REFRESH_INTERVAL times (currently 1/0.25 = 4 per sec), there is huge amount of objects held in that variable.
After adding logger.info(f"_stack length: {len(self.__app.layout._stack)}")
to the __set_focus_automatically
function we got:
2023-01-25 08:53:02.518 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 3
2023-01-25 08:53:02.790 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 5
2023-01-25 08:53:03.056 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 6
2023-01-25 08:53:03.308 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 7
2023-01-25 08:53:03.541 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 8
2023-01-25 08:53:03.802 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 9
2023-01-25 08:53:04.049 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 10
2023-01-25 08:53:04.299 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 11
2023-01-25 08:53:04.545 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 12
2023-01-25 08:53:04.796 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 13
2023-01-25 08:53:05.071 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 14
2023-01-25 08:53:05.298 | ℹ️ INFO | clive.app:__set_focus_automatically:51 - _stack length: 15
Also apart from increasing memory occupancy, this will cause the application to slow down with time since some internals of prompt_toolkit are iterating over _stack
FYI @kmochocki
Edited by Mateusz Żebrak