[sugar] Removing docstrings

C. Scott Ananian cscott
Tue Aug 26 15:33:45 EDT 2008


On Tue, Aug 26, 2008 at 1:00 PM, Tomeu Vizoso <tomeu at tomeuvizoso.net> wrote:
> Anybody with python knowledge can comment on this? Would have expected
> a significantly smaller number of objects in the GC:
>
> tomeu at tomeu-laptop:~/sugar-jhbuild/source/sugar$ python
> Python 2.5.2 (r252:60911, May  7 2008, 15:19:09)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import gc
>>>> len(gc.get_objects())
> 2508
>>>> import gtk
>>>> len(gc.get_objects())
> 12272
>
> tomeu at tomeu-laptop:~$ python -OO
> Python 2.5.2 (r252:60911, May  7 2008, 15:19:09)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import gc
>>>> len(gc.get_objects())
> 2506
>>>> import gtk
>>>> len(gc.get_objects())
> 12270

I think gc.get_objects() is lying to you.  Here's the simple test I tried:

--- test.py ---
#!/usr/bin/python2.5
"""This is a docstring."""

class Foo(object):
    """This is another docstring."""
    pass

import gc
print len(gc.get_objects())
---- eof ---

cananian at skiffserv:~/Desktop$ python2.5 ./test.py
2479
cananian at skiffserv:~/Desktop$ python2.5 -OO ./test.py
2476

So far so good, right?  A little puzzling because there are only two
docstrings, but python seems to be saying we saved *three* objects
with -OO.  But look at this:

$ python2.5
Python 2.5.2 (r252:60911, Aug  8 2008, 09:22:44)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import gc
>>> print len(gc.get_objects())
19026
>>> numpy.__doc__ = None
>>> print len(gc.get_objects())
19026
>>>

You can play around with this yourself, verifying that numpy.__doc__
had a doc string before the first call, checking that gc.collect()
doesn't affect the results, etc.  Bottom line is that gc.get_objects()
doesn't seem to be counting docstrings.
 --scott

-- 
 ( http://cscott.net/ )



More information about the Sugar-devel mailing list