[issue15490] Correct __sizeof__ support for StringIO

Serhiy Storchaka report at bugs.python.org
Mon Jul 30 10:14:11 CEST 2012


Serhiy Storchaka added the comment:

> For the PyAccu, AFAICT, objects cannot leak out of it (except for gc.getobjects in debug mode).

Not only in debug mode.

>>> import io, gc
>>> s=io.StringIO()
>>> s.write('12345')
5
>>> s.write('qwerty')
6
>>> for o in gc.get_objects():
...     if "'123" in repr(o) and len(repr(o)) < 1000:
...         print(type(o), repr(o))
... 
<class 'list'> ['12345', 'qwerty']
<class 'list'> ['o', 'gc', 'get_objects', 'repr', 'o', "'123", 1000, 'len', 'repr', 'o', 'print', 'type', 'o', 'repr', 'o']
<class 'tuple'> ("'123", 1000, None)

Someone can summarize sys.getsizeof() for all managed by GC objects and therefore count internal objects twice.

I think the standard library should provide a method for recursive calculation of memory (in some sense, perhaps using different strategies), but that should wait up to 3.4. __sizeof__ should count non-object memory that is not available for GC. As I understand it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15490>
_______________________________________


More information about the Python-bugs-list mailing list