Embedding Python - Deleting a class instance
Andreas Kostyrka
andreas at kostyrka.org
Wed Jun 22 05:03:27 EDT 2005
On Tue, Jun 21, 2005 at 12:06:47PM +0000, Bue Krogh Vedel-Larsen 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 :)
>
> I've noticed that the PyObject returned by PyInstance_New has refcount = 2,
> does this have any significance?
Well, the only way to do that is to call PyDECREF. And this is only legal
when you really remove the reference, or else you get dangling pointers
which will lead to a corrupted heap and/or segfault somewhere in the future of
your program.
Andreas
More information about the Python-list
mailing list