Replies: 1 comment 2 replies
-
Hi @dsuedholt, can you check again with the latest |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! While using nanobind, I ran into pretty much the exact issue previously described here.
Just to provide an as-minimal-as-possible example, using the following bindings in C++:
and calling them from a Python script like so:
will trigger nanobind's memory leak warnings:
As per @wjakob's reply in that thread, simply moving the Python snippet from the global scope into a function makes the warnings disappear. So does adding an explicit
del b
statement to the end of the script.Both that reply and the FAQ section in the docs mention that this is a problem with older python versions. However, the example above produces the same warnings under current versions as well (I tested 3.11, 3.12, and 3.13).
I'm wondering if the FAQ bullet point "Older Python Versions" should be changed to something like "References in the global scope" instead? I could have probably saved some time and frustration if I had tried the workaround of avoiding global scope immediately, but I initially dismissed the "older version" potential reason since I was using 3.13.
Additionally, would it be fair to say that for a library of bindings distributed as a package, disabling nanobind's leak warnings entirely is almost mandatory at the moment? Otherwise everyone who installs the package and uses it in the global scope, or simply in a REPL, would be shown the warnings.
Beta Was this translation helpful? Give feedback.
All reactions