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 refe开发者_StackOverflow社区rence 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?
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.
精彩评论