Replies: 1 comment
-
It's not supported by stock nanobind. You might be able to achieve such features by modifying the library -- however, that is beyond the scope of this support forum. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to manage ownership using std::unique_ptr in C++, while obtaining only weak references in Python? When the unique_ptr is destroyed, the weak references in Python should also become invalid simultaneously.
Recently, I implemented something similar, an intrusive C++ UniqueObject that holds a pointer to additional block for storing the reference count of weak references. However, when converting weak references to Python, an object needs to be created each time, resulting in additional overhead, and the created weak references are not the same object.
I'm wondering if it's possible to simply mark the Python object associated with the weak reference as invalid when the UniqueObject is destroyed. Later, when using the weak reference's Python object, an exception could be thrown if the object has been marked invalid.
Beta Was this translation helpful? Give feedback.
All reactions