Embedding Python - Deleting a class instance
Denis S. Otkidach
ods at strana.ru
Tue Jun 21 08:32:31 EDT 2005
On Tue, 21 Jun 2005 12:06:47 GMT
"Bue Krogh Vedel-Larsen" <hesterumpe at tiscali.dk> wrote:
> How do I delete a class instance created using PyInstance_New? I've tried
> calling Py_CLEAR on the instance, but __del__ isn't called. I've also tried
> calling PyObject_Del, but this gives an access violation in
> _PyObject_DebugDumpAddress so I guess that ain't a good idea :)
It is deleted automatically when reference count become zero or when
garbage collector runs if the object contains references to itself.
Just call Py_DECREF on it if you are not going to use it anymore.
> I've noticed that the PyObject returned by PyInstance_New has refcount = 2,
> does this have any significance?
The code below prints 1:
PyObject *obj = PyInstance_New(PyExc_Exception, 0, 0);
std::cerr << obj->ob_refcnt << "\n";
Does it create circular references in constructor?
--
Denis S. Otkidach
http://www.python.ru/ [ru]
More information about the Python-list
mailing list