开发者

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 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜