This question has already been answered:
I have a question on the default parameters of functions . That is, by
>>> def foo(my_list=[]): ... my_list.append(1) ... return my_list ... >>> foo() [1] >>> foo() [1, 1] >>> foo() [1, 1, 1] >>> I understand why this is happening (the question of the rationality of such behavior will be left outside)
Do I understand correctly that if I call a function once with such a default list, where to fill it with a gigabyte of data, return, use and then forget, then the memory will still be held due to the default [] pinned to def foo?
del foo. - insolor