pybind / pybind/pybind11

Cleanup internals for garbage-collected `py::class_` objects

Open
#2,595 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

In case we'd forget, @EricCousineau-TRI made some good remarks on #2564, that we should still attend to:

Not sure if it'd be easily addressable, but there may be lingering references from other types here:

https://github.com/pybind/pybind11/blob/7c71dd386161703dc25860870f579cca0ff3a9a8/include/pybind11/detail/internals.h#L135-L137

e.g. you're freeing type A, but type B has a conversion related to that type


  • implicit_casts looks like it's only used for MI, so by construction I don't think you'd have a dangling parent base.
  • direct_conversions looks like it's only used for NumPy dtypes
  • implicit_conversions looks like it requires that both types be alive, so also should be fine. However, you may have unbounded memory growth (e.g. multiple registrations for a re-registered C++ class)

So yeah, looks like everything is fine. Just may want to make a minor note on implicit_conversiosn being unbounded; however, it's unlikely that unbounded growth will matter much? (unless someone likes running the GC every 30sec for 24hrs?)

Originally posted by @EricCousineau-TRI in https://github.com/pybind/pybind11/pull/2564#discussion_r504003987

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with include/pybind11/detail/internals.h at the referenced lines and read PR #2564, then trace how implicit_casts, direct_conversions, and implicit_conversions retain type references. Done means determining whether garbage-collected py::class_ objects can leave dangling or unbounded conversion entries and recording the justified cleanup or note.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.