Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leak report #19

Closed
tbrekalo opened this issue Apr 6, 2022 Discussed in #13 · 5 comments
Closed

leak report #19

tbrekalo opened this issue Apr 6, 2022 Discussed in #13 · 5 comments

Comments

@tbrekalo
Copy link

tbrekalo commented Apr 6, 2022

Discussed in #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)

@wjakob
Copy link
Owner

wjakob commented Apr 9, 2022

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.

@xk-huang
Copy link

xk-huang commented Sep 1, 2022

I also encountered the leak issue rgl-epfl/cholespy#10 (comment).
But I have no idea how to solve it.

@wjakob
Copy link
Owner

wjakob commented Oct 13, 2022

@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)

@wjakob wjakob closed this as completed Oct 13, 2022
@wjakob
Copy link
Owner

wjakob commented Oct 13, 2022

I filed a bug with Python: python/cpython#98253

@xk-huang
Copy link

Thanks for your kind reply! the cleanup indeed worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants