How to get reference count of a PyObject?

后端 未结 1 985
一个人的身影
一个人的身影 2021-02-19 15:14

How to get reference count of a PyObject from C++?

There are functions Py_INCREF and Py_DECREF which increase/decrease it, but I

1条回答
  •  爱一瞬间的悲伤
    2021-02-19 15:37

    The reference count of each and every object is stored in the PyObject itself, in a variable called ob_refcnt. You can directly access that.

    typedef struct _object {
        _PyObject_HEAD_EXTRA
        Py_ssize_t ob_refcnt;          # Reference count
        struct _typeobject *ob_type;
    } PyObject;
    

    Alternatively, you can use the Py_REFCNT Macro.

    0 讨论(0)
提交回复
热议问题