[Python-Dev] Does eval() leak?

John Marshall John.Marshall at ec.gc.ca
Thu Feb 16 17:30:02 CET 2006


Hi,

Should I expect the virtual memory allocation
to go up if I do the following?
-----
raw = open("data").read()
while True:
	d = eval(raw)
-----

I would have expected the memory allocated to the
object referenced by d to be deallocated, garbage
collected, and reallocated for the new eval(raw)
results, assigned to d.

The file contains a large, SIMPLE (no self refs; all
native python types/objects) dictionary (>300K).

While doing 'd = eval(raw)' in the python interpreter
I am monitoring the VIRT column of top and it keeps
increasing until I run out of memory.

When I use a safe_eval() from:
     http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
I have no memory problems.

I see this under python 2.3.5 (fast and obvious).

Thanks,
John



More information about the Python-Dev mailing list