Why does this leak memory?

Ian Kelly ian.g.kelly at gmail.com
Thu Jun 7 18:31:02 EDT 2012


On Thu, Jun 7, 2012 at 12:48 PM, Steve <no at spam.com> wrote:
> The leaks can be removed by uncommenting both lines shown.

That's just a matter of timing.  You call the function before you call
set_debug, so when you uncomment the lines, the garbage collector is
explicitly run before the debug flags are set.  When it runs again
later, there are no collectable objects for it to find, as they've
already been collected.  With the lines commented, the garbage
collector doesn't get run until after the set_debug call, so it finds
the collectable objects at that time.  Either way the objects get
collected sooner or later, so I don't see any leaks here.

Cheers,
Ian



More information about the Python-list mailing list