Skip to content

Leaks when binding nested classes with default values in itializer #895

Answered by wjakob
tom-bola asked this question in Q&A
Discussion options

You must be logged in to vote

There is a reference here that goes from a type object to an instance, which creates the potential for instance <-> type cycles. Something like that must be happening here, which is probably complicated to understand and related to Python implementation details related to type and module objects.

Nanobind instances are normally not registered with the GC, since this has a const. In this case, what I suspect is that the warning will go away if you provide at trivial Py_tp_visit callback that only visits the type object of the instance (see the testcases for example code). Can you try this and report back?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tom-bola
Comment options

Answer selected by tom-bola
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants