[Python-Dev] reference leaks, __del__, and annotations

James Y Knight foom at fuhm.net
Mon Apr 3 21:49:58 CEST 2006


On Apr 3, 2006, at 3:12 PM, Neil Schemenauer wrote:

> Guido van Rossum <guido at python.org> wrote:
>> This would require a bit "__del__ already called" on an object,
>> but don't we have a whole word of GC-related flags?
>
> No.

Actually there is. Kinda. Currently python's refcounting scheme uses  
4 words per object (gc_next, gc_prev, gc_refs, ob_refcnt), and has  
one spare word in the padding of PyGC_Head that's just sitting there  
wasting memory. So really it's using up 5 words per object, and that  
5th word could actually be used for flags...

/* GC information is stored BEFORE the object structure. */
typedef union _gc_head {
     struct {
         union _gc_head *gc_next;
         union _gc_head *gc_prev;
         int gc_refs;
     } gc;
     long double dummy;  /* force worst-case alignment */
} PyGC_Head;


#define PyObject_HEAD           \
     _PyObject_HEAD_EXTRA        \
     int ob_refcnt;          \
     struct _typeobject *ob_type;

typedef struct _object {
     PyObject_HEAD
} PyObject;


James


More information about the Python-Dev mailing list