6

I've wrapped a C++ class using Boost.Python. These Objects have strong references (boost::shared_ptr) on the C++-side, and there may be intermittent strong references in Python as well. So far, everything works well. However, if I create a python weak reference from one of the strong references, this weak reference is deleted as soon as the last python strong reference disappears. I'd like the weak reference to stay alive until the last strong reference on the C++ side disappears as well. Is it possible to achieve that?

Phrased another way: Is there a way to find out from python if a particular C++ object (wrapped by Boost.Python) still exists?

1 Answer 1

1

How are you holding a "C++ strong reference" to the wrapped class ?

I'm quite rusty on boost python, but I believe it's the boost::shared_ptr's deleter presence which ensures lifetime management.

If that isn't the problem, you probably need to hold the instance in C++ in a boost::python::object.

Sign up to request clarification or add additional context in comments.

1 Comment

As you suspected, I'm holding the strong reference in a boost::shared_ptr. I've clarified the question. Can you elaborate on the second paragraph? I can't seem to draw a connection to the issue - sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.