[issue3122] sys.getsizeof() gives an AttributeError for _sre objects.
Amaury Forgeot d'Arc
report at bugs.python.org
Fri Jun 27 11:49:03 CEST 2008
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
> Caching itself is no criteria, but allocating memory without giving
> the user a chance to find out should be (in this context).
> ... calling match.regs creates a
> tuple which is not there before, but cannot be removed
> afterwards. This is why I handled it separately.
Well, so why only include the tuple, and not objects inside the tuple?
They may also count in allocated memory (not often: small numbers are
shared)
Does the same criteria apply to function.func_defaults and function.doc
members? Both can be None, sizeof(None) would be added twice.
Would you say the same for property members?
class C(object):
def setx(self): self.__x = 42
x = property(lambda self: self.__x)
the value is not there before you call o.setx(), and cannot be removed
afterwards.
IMO, the criteria (to decide whether a container should include a
particular PyObject member in its sizeof) should not include the way the
member is created, or who created it, but only the current layout in
memory. For example: can other objects hold references to this member,
does it appear in gc.objects...
And I propose this simple algorithm: do not include any referenced
PyObject :-)
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3122>
_______________________________________
More information about the Python-bugs-list
mailing list