diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 8f6764879c..5352e4d258 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -7,6 +7,7 @@
#include "pycore_moduleobject.h" // _PyModule_GetDef()
#include "pycore_object.h"
#include "pycore_pyerrors.h"
+#include "pycore_pymem.h"
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_unionobject.h" // _Py_Union(), _Py_union_type_or
#include "frameobject.h"
@@ -1453,7 +1454,12 @@ subtype_dealloc(PyObject *self)
&& !(base->tp_flags & Py_TPFLAGS_HEAPTYPE));
assert(basedealloc);
+ if (Py_REFCNT(type) == 1) {
+ printf("subtype_dealloc(%s): call basedealloc() with Py_REFCNT(type)=1\n", type->tp_name);
+ }
+ assert(!_PyMem_IsPtrFreed(type->tp_name));
basedealloc(self);
+ assert(!_PyMem_IsPtrFreed(type->tp_name));
/* Can't reference self beyond this point. It's possible tp_del switched
our type from a HEAPTYPE to a non-HEAPTYPE, so be careful about