简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM