diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 04f5affb97902..4ef07525e7f63 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -441,6 +441,7 @@ static void Dealloc(PyObject* pself) { // Remove from interned dictionary interned_descriptors->erase(self->descriptor); Py_CLEAR(self->pool); + PyObject_GC_UnTrack(pself); Py_TYPE(self)->tp_free(pself); } diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index b2e561584045a..af494753e2b5f 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -210,6 +210,7 @@ static void Dealloc(PyObject* pself) { delete self->pool; } delete self->error_collector; + PyObject_GC_UnTrack(pself); Py_TYPE(self)->tp_free(pself); } diff --git a/python/google/protobuf/pyext/message_factory.cc b/python/google/protobuf/pyext/message_factory.cc index 872ce1836f32e..d8d68312d7ea0 100644 --- a/python/google/protobuf/pyext/message_factory.cc +++ b/python/google/protobuf/pyext/message_factory.cc @@ -89,6 +89,7 @@ static void Dealloc(PyObject* pself) { delete self->classes_by_descriptor; delete self->message_factory; Py_CLEAR(self->pool); + PyObject_GC_UnTrack(pself); Py_TYPE(self)->tp_free(pself); }