gc.get_referrers trouble

Skip Montanaro skip at pobox.com
Tue Sep 7 20:16:44 CEST 2004


    Diez> import gc
    Diez> a = [1]
    Diez> print  gc.get_referrers(1)

    Diez> Running that from bash gives me this:

    Diez> # python /tmp/test.py | wc
    Diez>      23    7196   67165

    Diez> Now I'm confused - how do I interpret the results of
    Diez> get_referrers() correctly?

Try your test with an object that's not massively shared:

    % python
    Python 2.4a2 (#46, Aug 29 2004, 08:53:23) 
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    import>>> import gc
    >>> a = [1000]
    >>> print gc.get_referrers(1000)
    [(1000, None)]

CPython maintains a list of small integers (range(-1, 100) I believe) that
are reused and shared.

Skip



More information about the Python-list mailing list