From 08a8ef3b092ad1203f8f1a062ea375904f46009f Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Thu, 24 Mar 2022 17:27:03 +0000 Subject: [PATCH] ugui.py: Enable user to disable GC. --- README.md | 10 ++++++---- gui/core/ugui.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d8d369e..5022692 100644 --- a/README.md +++ b/README.md @@ -891,10 +891,12 @@ explicitly in code. ## 4.5 Bound variable - * `pause_ms=0` Screen refreshes are performed by a looping task. This - refreshes the screen before pausing. The default of 0ms allows other tasks to - be scheduled and suffices in the vast majority of cases. In some applications - with difficult realtime requirements a longer pause can offer benefits. + * `do_gc = True` By default a coroutine is launched to periodically perform + garbage collection (GC). On most platforms this reduces latency by doing GC + before too much garbage has accumulated. However on platforms with SPIRAM GC + can take hundreds of ms, causing unacceptable latency. If `do_gc` is `False` + the application can perform GC at times when fast response to user actions is + not required. ## 4.6 Usage diff --git a/gui/core/ugui.py b/gui/core/ugui.py index 3142cb8..08add30 100644 --- a/gui/core/ugui.py +++ b/gui/core/ugui.py @@ -505,7 +505,7 @@ class Screen: async def _garbage_collect(self): n = 0 - while True: + while Screen.do_gc: await asyncio.sleep_ms(500) gc.collect() gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())