dealloc function in python extend c module

Shen, Yu-Teh shenyute at gmail.com
Thu Jul 2 02:11:54 EDT 2009


I create my extend type something like http://www.python.org/doc/current/extending/newtypes.html.
And my type has a member which is a pointer point to my allocate
memory ( no ref count).
ex:
---------------------------------------------------
typedef struct {
    PyObject_HEAD
    /* Type-specific fields go here. */
    mytype *p;
} noddy_NoddyObject;

And i write dealloc function like this:
---------------------------------------------------
static void
Noddy_dealloc(Noddy* self)
{
    delete p;
    self->ob_type->tp_free((PyObject*)self);
}

And I found it's strange that it didn't call dealloc when there is no
reference.

ex:
a = Noddy()
b = a
del a
del b
# i think there is no ref to the object, and it should call dealloc
but it didn't call!!!

could anyone tell me what happened?

Thanks a lot!!




More information about the Python-list mailing list