closing StringIO objects

Alex Martelli aleax at mac.com
Wed Aug 15 11:55:11 EDT 2007


Neil Cerutti <horpner at yahoo.com> wrote:

> The documentation says the following about StringIO.close:
> 
>   close( ) 
>   Free the memory buffer. 
> 
> Or else... what? 

Or else the memory buffer sticks around, so you can keep calling
getvalue as needed.  I believe the freeing will happen anyway,
eventually, if and when the StringIO instance is garbage collected (just
like, say, a file object's underlying fd gets closed when the file
object is garbage collected), but relying on such behavior is often
considered a dubious practice nowadays (given the existence of many
Python implementations whose GC strategies differ).


Alex



More information about the Python-list mailing list