Battle of the garbage collectors, or ARGGHHHHHH!!!!

Cem Karan cfkaran2 at
Tue Apr 25 15:31:05 EDT 2017

On Apr 24, 2017, at 8:54 PM, Jon Ribbens <jon+usenet at> wrote:

> On 2017-04-24, CFK <cfkaran2 at> wrote:
>> Long version: I'm trying to write bindings for python via ctypes to control
>> a library written in C that uses the bdwgc garbage collector (
>>  The bindings mostly work, except for when
>> either bdwgc or python's garbage collector decide to get into an argument
>> over what is garbage and what isn't, in which case I get a segfault because
>> one or the other collector has already reaped the memory.
> Make your Python C objects contain a pointer to a
> GC_MALLOC_UNCOLLECTABLE block that contains a pointer to the
> bwdgc object it's an interface to? And GC_FREE it in tp_dealloc?
> Then bwdgc won't free any C memory that Python is referencing.

That's a really clever idea… I'm not near the machine that I could test it on right now, but I'll give it a shot tomorrow and see how it works.  I'll let everyone know what I find out.

Cem Karan

More information about the Python-list mailing list