Some code:
import cStringIO
def f():
buffer = cStringIO.StringIO()
buffer.write(\'something\')
return buffer.getvalue()
The docume
From the source:
class StringIO:
...
def close(self):
"""Free the memory buffer.
"""
if not self.closed:
self.closed = True
del self.buf, self.pos
So StringIO.close
just frees the memory buffer deleting references to StringIO.buf
and StringIO.pos
. But if self
is garbage collected, its attributes will also be garbage collected, having the same effect as StringIO.close
.