__del__ warnings apply to tp_dealloc?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jey Kottalam

    __del__ warnings apply to tp_dealloc?

    Hi,

    The Python 2.3 Language Reference cautions that __del__ is not guarnateed to
    be invoked at
    http://www.python.org/doc/current/re...n.html#l2h-175 . I am
    writing a Python extension in C and I was wondering if the same precautions
    apply to tp_dealloc, that is, is there a possibility that the tp_delloc for
    my type may not be invoked?

    Thanks in advance,
    Jey Kottalam


  • Greg Chapman

    #2
    Re: __del__ warnings apply to tp_dealloc?

    On Mon, 2 Feb 2004 21:29:15 -0800, "Jey Kottalam" <kottalam@cs.uc davis.edu>
    wrote:
    [color=blue]
    >Hi,
    >
    >The Python 2.3 Language Reference cautions that __del__ is not guarnateed to
    >be invoked at
    >http://www.python.org/doc/current/re...n.html#l2h-175 . I am
    >writing a Python extension in C and I was wondering if the same precautions
    >apply to tp_dealloc, that is, is there a possibility that the tp_delloc for
    >my type may not be invoked?
    >[/color]

    Yes, there is no guarantee that all tp_deallocs will be called when the
    interpreter exits. In CPython, the interpreter does try to clean up when it
    exits by clearing out all the modules, which will generally cause most objects
    to have their tp_dealloc called. However, if the object is in a refcount cycle,
    there is no guarantee that the cycle will get collected.

    Note also that, unlike a python __del__ method, a tp_dealloc method will not
    keep the garbage collector from collecting cycles.

    ---
    Greg Chapman

    Comment

    Working...