Saturday 10:50 a.m.–11:20 a.m.

Track memory leaks in Python

Victor Stinner

Audience level:
Python Core (language, stdlib, etc.)


Memory leaks in Python cannot be analyzed with traditional tools because Python uses reference counters. I will present tools specific to Python to help you to localize your memory leaks.


* Global memory consumption of the process (RSS memory) * Understand reference cycles * Generate a picture representing links between objects * Use `gc.get_objects()` and "manually" compute the size of objects * [PEP 445][1]: "Add new APIs to customize Python memory allocators" implemented in Python 3.4 * Use the [pytracemalloc][3] module ([PEP 454][2]) to trace memory allocations at their creation * Use [pyfailmalloc][4] module to inject MemoryError in your application to test how it behaves in low memory condition [1]: [2]: [3]: [4]: