If I am using the take_ownership return value policy in pybind11, and I invoke a function that returns, say, a std::vector<Dog>, how can I ensure that the vector and its contents' destructors are called? Does it have anything to do with going out of scope in the python client code?
Things will be destructed when Python garbage collects the object (and invokes the CPython API hooks).
See here for Python docs:
https://docs.python.org/3.7/reference/datamodel.html#objects-values-and-types https://docs.python.org/3.7/reference/datamodel.html#object.del
Objects are never explicitly destroyed; however, when they become unreachable they may be garbage-collected. [...]
Specific to pybind, here're the dellocation bits that are invoked upon deletion:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With