Closed WJCFerguson closed 3 years ago
Similar with context manager:
>>> with pynng.Pub0() as pub:
... pass
>>> pub
<pynng.nng.Pub0 object at 0x7f006bdc2850>
>>> pub = None
>>> [o for o in gc.get_objects() if isinstance(o, pynng.Pub0)]
[<pynng.nng.Pub0 object at 0x7f006bdc2850>]
>>>
>>> gc.get_referrers([o for o in gc.get_objects() if isinstance(o, pynng.Pub0)][0])
[<cdata 'void *' handle to <pynng.nng.Pub0 object at 0x7f006bdc2850>>, [<pynng.nng.Pub0 object at 0x7f006bdc2850>]]
Thank you for the detailed bug report, this is very helpful! I'll see if I can track this down.
Turns out there is a reference cycle, so the socket is not collected immediately, but when the full garbage collection is run the sockets are collected as they should be. I just added a new test to ensure that sockets are collected, and in the test I manually call gc.collect()
to make sure that the sockets are collected.
Thanks for opening the issue!
Hey thanks for this, and sorry for the bother. I thought about gc.collect()
after I sent this, but was away from the computer and forgot. It's a while since I was messing with garbage collection, but I should have known.
Even if I call
close()
, it seems they are never gc'd? e.g.:Is this not a bug? Thanks.