A garbage collector for C and C++
hpl.hp.com
hpl.hp.com
personally, i am of the opinion that RAII-style object lifetime management as implemented in C++ is already far superior to garbage collection. but maybe somebody can convince me otherwise.
(Yeah, I've used it, in a scripting language I wrote for a commercial product in the '90s. No troubles.)
Ever single (good) programmer I know is aware of Hans-Boehm GC, but doesn't use it for any projects. In fact I am yet to see a project that uses it and I've seen quite a lot of them to date.
We were able to pretty easily integrate it into the project (we already had macros indirecting all calls to malloc() and free()) and initially use it as a leak detector. After that we were able to trust it to handle deallocation where it made sense.
A neat feature of this collector is that you can tell it during allocation that a block is guaranteed to have no pointers in it for those cases where you can know that (blacklisting big chunks of floating point data or images). This improves the performance and accuracy of the conservative collection as it doesn't need to scan those blocks. That makes it less objectionable if you are accustomed to the level of control you get with C.
If I were to build a big system in C again, I would use it from the beginning. But I am unlikely to build such a big system in C these days.
Two of the "can't handle" cases are: (1) the XOR trick to represent the prev/next pointer for a doubly-linked list with a single field. (2) Ullman's set set representation which uses an array of values which may, or may not, be valid pointers. You don't know without consulting another structure. (The whole point of this representation is that you don't clear things on initialization.)