Skip to content

Commit fd50623

Browse files
committed
weakref comment
1 parent 83e8076 commit fd50623

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

aiodns/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ def _make_channel(self, **kwargs: Any) -> tuple[bool, pycares.Channel]:
139139
raise RuntimeError(WINDOWS_SELECTOR_ERR_MSG)
140140
except ModuleNotFoundError as ex:
141141
raise RuntimeError(WINDOWS_SELECTOR_ERR_MSG) from ex
142-
# Use weak reference to avoid preventing garbage collection
142+
# Use weak reference for deterministic cleanup. Without it there's a
143+
# reference cycle (DNSResolver -> _channel -> callback -> DNSResolver).
144+
# Python 3.4+ can handle cycles with __del__, but weak ref ensures
145+
# cleanup happens immediately when last reference is dropped.
143146
weak_self = weakref.ref(self)
144147

145148
def sock_state_cb_wrapper(

0 commit comments

Comments
 (0)