python: fix nanobind Network reference leak via GC type slots

The Python Network holds each PyNode's callable, forming an
uncollectable instance -> callable -> globals() -> instance cycle that
tripped nanobind's leak check at interpreter shutdown.

Implement tp_traverse/tp_clear type slots on the Network binding so
Python's cyclic collector can see through the C++-held callables and
break the cycle. PyNode exposes its callable; PyNetwork visits and
clears them. Wired into both binding sites (auto_bind and the legacy
register_py_network).
This commit is contained in:
2026-07-04 14:43:47 +02:00
parent 949c8134ef
commit c4538f03ca
2 changed files with 74 additions and 2 deletions
+1 -1
View File
@@ -247,7 +247,7 @@ void bind_network(nb::module_& m) {
nb::class_<IVariantNode<Variant>>(m, "INode");
nb::class_<Net>(m, "Network")
nb::class_<Net>(m, "Network", nb::type_slots(network_type_slots<Variant>()))
.def("__init__", [](Net* self) {
new (self) Net();
register_all_converters<Registry>(*self);