3 ms·
This comes down to the usual boring semantic argument over what the term "garbage collection" means. Instead, I'll use the term "automatic dynamic lifetime det
by kibwen 3y ago
This comes down to the usual boring semantic argument over what the term "garbage collection" means.
Instead, I'll use the term "automatic dynamic lifetime determination".
In a Java-style GC, there exists code that runs at runtime to determine whether or not the lifetime of a piece of memory can be determined to have expired.
In a reference-counted system, there exists code that runs at runtime to determine whether or not the lifetime of a piece of memory can be determined to have expired.
Of course, in the latter case the "code" is just checking a single counter rather than doing fancy concurrent root-tracing, but the similarity is established, and the alternatives are clearly delineable:
1) "Automatic static lifetime determination": this is what Rust does with ownership, by statically analyzing your code and automatically inserting code to free memory at statically-determined points.
2) "Manual static lifetime determination": this is the classic C-style memory management, where the author manually inserts code to free memory at statically-determined points.
- eru 3y ago> Of course, in the latter case the "code" is just checking a single counter rather than doing fancy concurrent root-tracing, but the similarity is established, and the alternatives are clearly delineable: [...] You also need to do some fancy tracing for reference counting, because when a big data structure 'dies', you need to trace it completely. Of course, reference counting also pays the price of fiddling with its counters on every single read. So every read-only workload turns into a read-write workload. Garbage collection has no such overhead until you start the collector. (Basically all the overhead is amortised.)