A detailed code walkthrough of how CPython implements memory management, including reference counting and garbage collection
Are you on Windows? On my Linux x86_64 machine `Py_ssize_t` is `8` bytes (not 4) and `void*` is `8`. Therefore *`ob_refcnt` is `8`* either way:
```c
// from object.h
struct _object { // typedef _object PyObject; in pytypedefs.h
__extension__
union {
Py_ssize_t ob_refcnt;
#if SIZEOF_VOID_P > 4
PY_UINT32_T ob_refcnt_split[2];
#endif
};
PyTypeObject *ob_type;
```
https://github.com/python/cpython/blob/42351c3b9a357ec67135b30ed41f59e6f306ac52/Include/object.h#L110-L134
```python
assert ctypes.sizeof(ctypes.c_void_p) == 8
assert ctypes.sizeof(ctypes.c_ssize_t) == 8
Are you on Windows? On my Linux x86_64 machine `Py_ssize_t` is `8` bytes (not 4) and `void*` is `8`. Therefore *`ob_refcnt` is `8`* either way:
```c
// from object.h
struct _object { // typedef _object PyObject; in pytypedefs.h
__extension__
union {
Py_ssize_t ob_refcnt;
#if SIZEOF_VOID_P > 4
PY_UINT32_T ob_refcnt_split[2];
#endif
};
PyTypeObject *ob_type;
};
```
https://github.com/python/cpython/blob/42351c3b9a357ec67135b30ed41f59e6f306ac52/Include/object.h#L110-L134
```python
assert ctypes.sizeof(ctypes.c_void_p) == 8
assert ctypes.sizeof(ctypes.c_ssize_t) == 8
```