memory leak with dynamically defined functions?
Neil Schemenauer
nas at python.ca
Mon Jul 16 18:12:19 EDT 2001
Skip Montanaro wrote:
> zooko> But if I allocate memory and store a reference to it in a default
> zooko> argument to an inner function, like this:
>
> >>> def silliest_func():
> >>> x = [0] * (2**10)
> >>> def inner_silliest_func(x=x):
> >>> pass
> >>> return inner_silliest_func
> >>>
> >>> blarg = {}
> >>> for i in range(2**13):
> >>> blarg[i] = silliest_func()
>
> zooko> and then remove the references to this memory, like this:
>
> >>> del blarg
>
> zooko> none of the memory is freed up!
If I do this:
while 1:
blarg = {}
for i in range(2**13):
blarg[i] = silliest_func()
the Python process size seems to remain constant. Are you sure this
leaks memory? I'm testing with Python 1.5.2 BTW.
Neil
More information about the Python-list
mailing list