The C++ object has to keep a reference to the Python object and the Python object needs to keep a reference to the C++ object. See https://stackoverflow.com/questions/44993726/cyclic-reference-in-python-c-extension