← Back to context

Comment by pizlonator

1 day ago

The best part of these conversations is that if I say “garbage collection”, you have zero doubt that I am in fact referring to what you call “tracing garbage collection”.

You are defining reference counting as being a kind of garbage collection, but you can’t point to why you are doing it.

I can point to why that definition is misleading.

Reference counting as most of the industry understands it is based on destructors. The semantics are:

- References hold a +1 on the object they point to.

- Objects that reach 0 are destructed.

- Destruction deletes the references, which then causes them to deref the pointed at object.

This is a deterministic semantics and folks who use RC rely on it.

This is nothing like garbage collection, which just gives you an allocation function and promises you that you don’t have to worry about freeing.

> https://web.eecs.umich.edu/~weimerw/2008-415/reading/bacon-g...

They are different approaches for the same thing: automatic memory management. (Which is itself a not trivial to define concept)

One tracks liveness, while the other tracks "deadness", but as you can surely imagine on a graph of black and white nodes, collecting the whites and removing all the others vs one by one removing the black ones are quite similar approaches, aren't they?

  • You’re not going to convince me by citing that paper, as it’s controversial in GC circles. It’s more of a spicy opinion piece than a true story.

    I agree that RC and GC are both kinds of automatic memory management.

    RC’s semantics aren’t about tracking deadness. That’s the disconnect. In practice, when someone says, “I’m using RC”, they mean that they have destructors invoked on count reaching zero, which then may or may not cause other counts to reach zero. If you squint, this does look like a trace - but by that logic everyone writing recursive traversals of data structures is writing a garbage collector

    • A RC algorithm implementation using a cycle collector, or deferred deletion on a background thread, to reduce stop the world cascade deletion impact, is....