4 ms·
Get garbage collected by what? Doesn’t Python use reference counting?
by staticautomatic 3y ago
Get garbage collected by what? Doesn’t Python use reference counting?
- d0mine 3y agoasyncio doesn't store strong references to tasks. It is your responsibility to keep the ref: https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task https://docs.python.org/3/library/asyncio-task.html#asyncio.... Consider organizing the code using TaskGroup.
- jph00 3y agoPython has a GC.
- foresto 3y agoThe reference implementation (CPython) does use reference counting, but that is not its only approach to garbage collection. "The default build implementation is a generational collector. The free-threaded build is non-generational; each collection scans the entire heap." https://devguide.python.org/internals/garbage-collector/ https://devguide.python.org/internals/garbage-collector/ https://docs.python.org/3/library/gc.html https://docs.python.org/3/library/gc.html (And as someone else pointed out, asyncio's event loop keeps only weak references to tasks, so the GC implementation doesn't really matter here.)