Mitsuhiko on reddit brings up a good issue that I was not aware of: a bug in exec.
code=""" class Foo(object): def __del__(self): pass foo = Foo() """ while True: exec code in {} causes a memory leak. Web2py does this. The memory leak is small in practice and in fact nobody noticed it. Yet it is a concern, in theory. So far I have the current solution code=""" class Foo(object): def __del__(self): pass foo = Foo() """ import gc while True: exec code in {} gc.collect() It works for me and I cannot reproduce the leak. I patched trunk with this. Give it a try and let me know what you think. Massimo