def _garbage_collect(): while True: await asyncio.sleep_ms(500) gc.collect() gc.threshold(gc.mem_free() // 4 + gc.mem_alloc())