Paul Manta
Paul Manta

Reputation: 31567

Boost.Python: Weak reference to object?

Is there a way to get a weak reference to a Python object? With boost::python::object you get a strong/shared reference so as long as either C++ or Python holds a reference to that object, it will not get deleted. I want only Python to hold a strong reference to an object, and C++ a weak one. Is that possible?

Upvotes: 2

Views: 559

Answers (1)

Cat Plus Plus
Cat Plus Plus

Reputation: 129754

You need to go into the CPython API for that. Use PyWeakReference type from weakrefobject.h. The header exposes an API that's similar to weakref module — see the docs.

Upvotes: 4

Related Questions