Skip to content

Cleanup internals for garbage-collected py::class_ objects #2595

Description

@YannickJadoul

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:

std::vector<PyObject *(*)(PyObject *, PyTypeObject *)> implicit_conversions;
std::vector<std::pair<const std::type_info *, void *(*)(void *)>> implicit_casts;
std::vector<bool (*)(PyObject *, void *&)> *direct_conversions;

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 #2564 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions