[Python-Dev] A cute new way to get an infinite loop
Tim Peters
tim.peters at gmail.com
Thu Sep 23 20:11:34 CEST 2004
[Marek Baczek Baczyński]
> Doesn't it leak memory when Ctrl+C'd (on Windows at least?)
Not really. "Leak" is reserved for cases where memory is unaccounted
for. In this case, the memory is consumed by the ever-growing list:
>>> x = [1]
>>> x.extend(-y for y in x)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in <generator expression>
KeyboardInterrupt
>>> len(x)
67090195
>>> x[:10]
[1, -1, 1, -1, 1, -1, 1, -1, 1, -1]
>>>
At that point, doing
>>> del x[:]
reclaimed a few hundred megabytes.
More information about the Python-Dev
mailing list