-
Notifications
You must be signed in to change notification settings - Fork 763
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
Py::drop_ref #3870
Comments
Note that Lines 454 to 460 in 0bb9cab
i.e. it does not unconditionally queue up the change in the global The Would not open a pull request proposing that addition? |
Woops, my mistake - thanks for the correction :) I'll submit a PR for the micro-optimisation method still. |
The documentation for
Py
currently states that(https://docs.rs/pyo3/latest/pyo3/prelude/struct.Py.html#a-note-on-python-reference-counts)
However,Py
's drop impl seems to unconditionally callgil::register_decref
to defer the decref even when the GIL is currently held (https://docs.rs/pyo3/latest/src/pyo3/instance.rs.html#1010-1014). This may be needed for performance but makes explicit memory management difficult.EDIT (thanks @adamreichold):
Py
's drop impl callsgil::register_decref
which checks if the GIL is held to execute the decref immediately or defer it, which can be expensive.In parallel to the explicit
Py::clone_ref
, I propose adding the followingPy::drop_ref
method that can be used to explicitly drop aPy
if we already hold the GIL:The text was updated successfully, but these errors were encountered: