[Python-Dev] refleak hunting fun!

Tim Peters tim.one at comcast.net
Fri Aug 15 12:07:49 EDT 2003

> If this was available via regrtest using a command line flag,
> couldn't you do something like
>     python regrtest.py -L test_codeccallbacks
> to perform leak testing on just the one test suite?  That would make
> it go a lot faster when trying to squash particular leaks, as long as
> they weren't related to other tests.

Again it's a good idea to look at Zope's test drivers.  For example,


implements an -L switch:

    Keep running the selected tests in a loop.  You may experience
    memory leakage.

In a debug build, that also automatically uses the TrackRefs class to break
down leaks by object type leaking, and by nature (leaking new objects vs
merely accumulating excess references without leaking new objects).

Beware overdoing it, though!  Once the initial leaks found are plugged, new
ones are almost certainly caused by recent changes, and so much easier to
find.  A ton of delicate leak-tracking framework becomes counterproductive
then.  I think the Zope3 test driver (above) strikes a good balance.

More information about the Python-Dev mailing list