-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[FEAT] keep_alive_impl should admit reference cycles, and ideally be released by GC? #2761
Comments
Related references about CPython GC can be seen here: Note: I will only be considering CPython as we do not use PyPy for our usage at present (Drake: https://github.com/RobotLocomotion/drake) |
Some thoughts after reading the CPython dev guide (https://devguide.python.org/garbage_collector/)
Additional steps:
On point (3) - @wlav, can I ask if y'all ever had to deal with this kind of thing in cppyy? |
Filed #2762 to show random stuff |
Keep in mind that it probably won't be possible to implement |
@EricCousineau-TRI: the equivalent of Also, cppyy uses life lines when python objects are used as buffers (I don't think it's possible to automatically support unicode properly without it), which pybind11 (AFAIK) does not do; and selectively for iterators, which pybind11 does, too (but for slightly different selections). It's for the former case that life lines are labelled to deal with replacement (usually with the pointer address on the C++ side for which the python object buffers). |
@rwgk and @dabrahams had a brief convo regarding this. Regarding (2): Ralf's question:
Dave's response:
|
Upstream motivation - memory leaks that don't get released:
RobotLocomotion/drake#14387
Basically, because of our usage of
unique_ptr
and how we've design our C++ public API and bindings (RobotLocomotion/drake#13058), there are some awkward edge cases when we have "opaque" memory transfers.This arose because we wanted to fix a segfault: RobotLocomotion/drake#14356
However, this reference cycle appears to grow without bounds.
TODO(me): Explicitly trygc.collect()
with aggressive collection arguments.See below: #2761 (comment)
I'm filing this now because @YannickJadoul mentioned that
keep_alive
may be useful for #1941 (py::dynamic_attr
coordinating with "mismatched" lifetime betweenpy::detail::instance
and the actualshared_ptr<T>
). Akeep_alive
may fix that issue in a more general way, but will admit reference cyclesNote: I am speculating that the current approach (based on Boost.Python, per @bmerry's comment in #880) doesn't admit GC collection when cycles are introduced. I should confirm this.
\cc @rwgk @rhaschke about this sharp edge case with
unique_ptr<>
(#2646)The text was updated successfully, but these errors were encountered: