[Python-Dev] C new-style classes and GC
Jeremy Hylton
jeremy@zope.com
16 May 2003 13:35:33 -0400
On Fri, 2003-05-16 at 13:08, Jim Fulton wrote:
> If you write types the New Way, there are no PyObject_New calls and
> no need to call PyObject_GC_Track.
I don't follow. There are plenty of types that are garbage collectable
that also use PyObject_GC_New. One example is PyDict_New(). If
something is widespread in the Python source tree (a common source of
example code for programmers), it ought to be documented.
> > It's not clear to me what the one right way to implement a tp_dealloc
> > slot is. I've seen two common patterns in the Python source: call
> > obj->ob_type->tp_free or call PyObject_GC_Del. The type object
> > initializes tp_free to PyObject_GC_Del, so in most cases the two
> > spellings are equivalent. Calling PyObject_GC_Del feels more
> > straightforward to me.
>
> You need to call obj->ob_type->tp_free to support subclassing.
>
> I suggest that every new type should call obj->ob_type->tp_free
> as a matter of course.
If the type is going to support subclassing.
Jeremy