You can get the list of referrers to your object, using gc.get_referrers
function, like this
import gc, pprint
pprint.pprint(gc.get_referrers("string"))
The reference count of each and every object is stored in the object itself, in a variable called ob_refcnt
typedef struct _object {
_PyObject_HEAD_EXTRA
Py_ssize_t ob_refcnt;
struct _typeobject *ob_type;
} PyObject;
And the Reference counts of the objects are incremented and decremented using the macros Py_INCREF
and Py_DECREF
respectively.
#define Py_INCREF(op) ( \
_Py_INC_REFTOTAL _Py_REF_DEBUG_COMMA \
((PyObject*)(op))->ob_refcnt++)
#define Py_DECREF(op) \
do { \
if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
--((PyObject*)(op))->ob_refcnt != 0) \
_Py_CHECK_REFCNT(op) \
else \
_Py_Dealloc((PyObject *)(op)); \
} while (0)