In the main branch, the function _tracemalloc__get_object_traceback doesn't account for objects with preheaders:
|
type = Py_TYPE(obj); |
|
if (PyType_IS_GC(type)) { |
|
ptr = (void *)((char *)obj - sizeof(PyGC_Head)); |
|
} |
|
else { |
|
ptr = (void *)obj; |
|
} |
|
|
|
traceback = tracemalloc_get_traceback(DEFAULT_DOMAIN, (uintptr_t)ptr); |
This means that when running with tracemalloc some allocation tracebacks are missing:
import warnings
class MyClass:
def __del__(self):
warnings.warn("Uh oh", ResourceWarning, source=self)
def func():
m = MyClass()
func()
python3 -Wd -X tracemalloc=2 example.py
cc @markshannon
Linked PRs