automatic reclaiminig of limited resources (was Re: [Python-Dev] Product iteration)

Guido van Rossum guido@beopen.com
Thu, 27 Jul 2000 08:44:26 -0500


> This rant is about automatically reclaimed resources like file descriptors.
> 
> First let me cite a few sentences from the ancient book "Programming Python"
> written by Mark Lutz (p.122).  Since this was the very first available book 
> on Python, it could be considered as some kind of Python Programmers Guide.
> Much existing code today relies on the lessons teached there:
> 
>   """The short answer is that all files in this program are closed 
>      automatically: there's no need to call the file object "close" method.
>      [...]
>      More specifically, Python uses a reference count garbage collection
>      strategy to reclaim memory behind the scenes.
>      [...]
>      each time we set 'input' to a new file in the for loop above, its
>      previous value can be reclaimed.
>      [...]
>      When a file object is reclaimed, the file is automatically closed
>      [...]
>      We usually don't need to close such files manually; 
>      [...]
>   """

At the time Mark wrote, this was true.  When JPython was introduced,
I realized that I couldn't guarantee this in all implementations, so I
removed that part of the language spec (at least in my head, and in
the collective memory of the Python community).

In any case, Moshe used this argument to defend weak binding to
references to outer variables from inside inner functions; but that
breaks closures, which is unacceptable.

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)