nanobind
nanobind copied to clipboard
leak report
Discussed in https://github.com/wjakob/nanobind/discussions/13
Originally posted by tbrekalo March 31, 2022 How do I interpret the following?
nanobind: leaked 1 types!
- leaked type "Pile"
nanobind: leaked 5 functions!
- leaked function "<anonymous>"
- leaked function "<anonymous>"
- leaked function "<anonymous>"
- leaked function "<anonymous>"
- leaked function "__init__"
nanobind: this is likely caused by a reference counting issue in the binding code.
Is it a bug on my part for getting something wrong in binding code or is it an issue with nanobind? Side note: code causing this issue deals with shared pointers for another type that is not brought up by the error message. Type 'Pile' is regular value type, I have a std::vector of them. So I am not sure how reference counting is being mentioned here.
Thanks for your help in advance.
Issue with false report of type leaks influenced by python type hints and imort of non-standard modules (in this case; seaborn 0.11)
Generally, interpreter shutdown is a tricky business in Python, but collectable instances (including heap types) should be collected, and a lot of work has been put into this by the CPython team. This is needed to correctly close sockets, flush buffers, etc. -- things that are essential for the program to work correctly. However, a reference leak normally does not generate an error/warning and can still be missed.
So when nanobind complains about things not being garbage collected, it deserves some scrutiny instead of disabling the warning.
In your case, what seems to be responsible is a binary extension module of pandas
that is imported by seaborn
. In particular, the following line triggers this reference counting issue
import pandas._libs
This is as far as I got.
I also encountered the leak issue https://github.com/rgl-epfl/cholespy/issues/10#issuecomment-1233807046. But I have no idea how to solve it.
@tbrekalo @xk-huang : This is not a pybind11 issue to my knowledge. I believe that the following snippet should fix it:
import atexit
def cleanup():
import typing
for cleanup in typing._cleanups:
cleanup()
atexit.register(cleanup)
I filed a bug with Python: https://github.com/python/cpython/issues/98253
Thanks for your kind reply! the cleanup
indeed worked.