I would like to associate the garbage-collected language (in particular using the venerable Boehm libgc) for the glib API family.
glib and gobject use internal reference counting to control the lifetime of an object. The usual way to wrap them is to use a garbage collected peer-to-peer object that contains a reference to the glib object and which discards the link when the peer completes; this means that the glib object remains alive while the application uses peer. I have done this before, and it works, but it is rather painful and has its own problems (for example, creating two peers of the same base object).
Given that in any case I have all the overhead of a garbage collector, ideally I would just like to turn off glib link counting and use the garbage collector for everything. This will simplify the interface endlessly and hopefully improve performance.
At first glance, this seems pretty simple - connect the garbage collector finalizer to the glib object finalizer and redefine the ref and unref functions, which will be noops --- but further research shows that this is more than that: glib likes to keep its own allocator pools, for example, and, of course, I let him do that the garbage collector assumes that everything in the pool lives and it will flow.
Is persuading glib to use libgc is actually doable? If so, what other errors can I encounter? What is the impact of glib performance forcing all distributions to go through the libgc product (as opposed to using optimized distributors currently in glib)?
(Glib docs say it should interact cleanly with the garbage collector ...)
source share