News for hackers. Stuff that matters.
Re:Show HN: A simple garbage collector for C by gwbas1c on Friday December 20, 2019 @09:53AM (#21844559)
Typically, new garbage collected languages use the Boehm garbage collector (GC for C) in early versions, and then implement their own once they have time to fully optimize their runtime.

This is what Mono and Golang did. (They both used Boehm until they had time and resources to implement their own runtime-optimized GC.) I suspect Java did too, but I'm not sure.

In this case: "The original motivation for gc is my desire to write my own LISP in C, entirely from scratch - and that required garbage collection."

What basically happens is that gc (and Boehm) are "conservative garbage collectors." They treat all values in a data structure as a potential pointer, because they don't know the contents of the data structure. It's a good "quick and dirty" way to have garbage collection if you can accept the risk that some of your memory will remain uncollected if some of your data happens to have the same value as one of your pointers. In practice, it's a good tradeoff.

(Other tradeoffs are that you can't have things like real-time garbage collection, generational garbage collection, or compacting garbage collection.)

> If you're going for a garbage collector, why not also benefit from some of the increased language power/features of a higher level language?

Ironically, one of Boehm's use cases is looking for memory leaks. You basically #ifdef Boehm into a test build, and if a GC finds garbage, you know that you didn't free something correctly.

Re:Show HN: A simple garbage collector for C by weberc2 on Friday December 20, 2019 @12:26PM (#21845756)
> Ironically, one of Boehm's use cases is looking for memory leaks. You basically #ifdef Boehm into a test build, and if a GC finds garbage, you know that you didn't free something correctly.

So a "garbage checker"? :) This is interesting, I never really thought about using it as a checking tool.

Re:Show HN: A simple garbage collector for C by djmips on Friday December 20, 2019 @06:32PM (#21848327)
Oddly enough, Unity a very popular game development platform ended up sticking with an early version of Mono and Boehm for a very long time (years) and I'm not even sure that it's fully transitioned to something newer yet. (anybody know?)