Skip to content

Question / possible bug leaking python object in binding #919

Answered by wjakob
awni asked this question in Q&A
Discussion options

You must be logged in to vote

I think this is an expected reference and unrelated to nanobind, i.e.: you would have a leak here with other binding frameworks as well, they just wouldn't warn you about it.

Your x function implicitly depends on globals(), which in turn contains y, which references x. To inform Python that this is a collectable cycle, you'll have to implement tp_traverse for your Test type.

This is actually a nice and concise way to illustrate a problem that people often aren't aware of, I think I'll integrate it into the FAQ.

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
6 replies
@awni
Comment options

@wjakob
Comment options

@awni
Comment options

@awni
Comment options

@awni
Comment options

Answer selected by awni
Comment options

You must be logged in to vote
3 replies
@awni
Comment options

@wjakob
Comment options

@awni
Comment options

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