Debugging reference counts in python/C

Discussion in 'Python' started by karmadharma@gmail.com, Aug 30, 2006.

  1. Guest

    Hello everybody

    I am trying to make sure that my (non trivial) C module is cleaning up
    properly after itself, and consequently I've built python with
    --py-debug which, besides allowing me to use certain functions, it also
    prints the reference count at the end.

    I am finding, however, that the reference count on exit seems to
    increase by 1 every time I create one of my objects, poring over the
    output of the debugging functions seems to imply that the only thing
    that changes is the refcount of

    [somenumber] '<dummy key>'

    where somenumber seems proportional to the number of objects I create,
    if I create n+1 objects, somenumber increases by 1. Looking at the docs
    this seems related to empty dictionaries, but I'm really stumped at the
    moment.

    Out of curiosity I also did this stupid test thinking it would return
    the same refcount, but evidently it doesn't:

    Type "help", "copyright", "credits" or "license" for more information.
    >>> a=1

    [17214 refs]
    >>> (ctrl-D)

    [17214 refs]
    [6606 refs]

    Type "help", "copyright", "credits" or "license" for more information.
    >>> a=1

    [17214 refs]
    >>> b=2

    [17217 refs]
    >>> (ctrl-D)

    [17217 refs]
    [6608 refs]

    as you can see just assigning another variable causes the refcount to
    remain higher when python exits.

    Is this something I should be worried about at all? I am new to writing
    python C extensions, and that's why I never really worried about all
    this before; apologies if my question is obvious and/or trivial...
    , Aug 30, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmFtZXNT?=

    ASP.NET Worker Process Thread Counts

    =?Utf-8?B?SmFtZXNT?=, Apr 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    639
    =?Utf-8?B?SmFtZXNT?=
    Apr 27, 2005
  2. raghu

    Reference Counts

    raghu, May 18, 2006, in forum: Python
    Replies:
    5
    Views:
    447
    Tim Peters
    May 19, 2006
  3. Jeremy Smith
    Replies:
    2
    Views:
    575
    Jeremy Smith
    Aug 3, 2006
  4. Replies:
    117
    Views:
    3,866
    Thomas J. Gritzan
    Apr 10, 2008
  5. Madhusudan.C.S
    Replies:
    406
    Views:
    5,070
    Michele Simionato
    Jan 28, 2009
Loading...

Share This Page