pytracemalloc 0.7: new tool to track memory leaks in Python

Victor Stinner victor.stinner at
Thu Mar 7 22:28:11 CET 2013


Wyplay is proud to announce the release of a new tool to track Python
memory allocations: "pytracemalloc".

pytracemalloc provides the following information:

- Allocated size and number of allocations per file,
  or optionally per file and line number
- Compute the average size of memory allocations
- Compute delta between two "snapshots"
- Get the source of a memory allocation: filename and line number

It helps to track memory leaks: show directly in which Python files
the memory increases.

Example of pytracemalloc output (compact):

    2013-02-28 23:40:18: Top 5 allocations per file
    #1: .../Lib/test/ 3998 KB
    #2: .../Lib/unittest/ 2343 KB
    #3: .../ctypes/test/ 513 KB
    #4: .../Lib/encodings/ 525 KB
    #5: .../Lib/compiler/ 438 KB
    other: 32119 KB
    Total allocated size: 39939 KB

Example of pytracemalloc output (full):

    2013-03-04 01:01:55: Top 10 allocations per file and line
    #1: .../2.7/Lib/ size=408 KiB (+408 KiB),
count=5379 (+5379), average=77 B
    #2: .../unittest/test/ size=401 KiB (+401 KiB),
count=6668 (+6668), average=61 B
    #3: .../2.7/Lib/ size=319 KiB (+319 KiB), count=197
(+197), average=1 KiB
    #4: .../Lib/test/ size=429 KiB (+301 KiB),
count=5806 (+3633), average=75 B
    #5: .../Lib/unittest/ size=162 KiB (+136 KiB),
count=452 (+380), average=367 B
    #6: .../Lib/test/ size=105 KiB (+105 KiB),
count=1125 (+1125), average=96 B
    #7: .../Lib/unittest/ size=77 KiB (+77 KiB),
count=1149 (+1149), average=69 B
    #8: .../Lib/test/ size=75 KiB (+75 KiB),
count=1644 (+1644), average=46 B
    #9: .../2.7/Lib/ size=64 KiB (+64 KiB), count=1000
(+1000), average=66 B
    #10: .../Lib/test/ size=56 KiB (+56 KiB),
count=932 (+932), average=61 B
    3023 more: size=1580 KiB (+1138 KiB), count=12635 (+7801), average=128 B
    Total: size=3682 KiB (+3086 KiB), count=36987 (+29908), average=101 B

To install pytracemalloc, you need to patch and recompile your own
version of Python to be able to hook all Python memory allocations.


Wyplay was created in March 2006 in the south of France. Independent,
Europe-based, and internationally recognized, Wyplay’s TV-centric
software solutions power the world’s most popular operator and
consumer electronic brand names. Targeted products includes:
Connected-HDTVs, Media Center CE devices, HD IPTV boxes, DVB-S/C/T HD
STBs, and in-home media-HDD products.


More information about the Python-announce-list mailing list