__del__ warnings apply to tp_dealloc?

G

Greg Chapman

Hi,

The Python 2.3 Language Reference cautions that __del__ is not guarnateed to
be invoked at
http://www.python.org/doc/current/ref/customization.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?

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top