3 ms·
Well, RAII 'fixes' the problem by making it uniformly complicated, instead of uniformly simple. For memory resources, there simply is no ownership in GC-land.
by tsimionescu 6y ago
Well, RAII 'fixes' the problem by making it uniformly complicated, instead of uniformly simple.
For memory resources, there simply is no ownership in GC-land. This frees you to use patterns that you just can't implement in RAII-only. Famously, atomic compare-and-swap for heap-allocated objects is much harder to implement with manual memory management (who owns the old pointer after a successful CAS?)[0].
And sure, situations where ownership is not clear are rare [1], but so are file handles that aren't immediately closed, so in practice GC + local RAII seems to cover a huge amount of cases.
[0] https://www.drdobbs.com/lock-free-data-structures/184401865 https://www.drdobbs.com/lock-free-data-structures/184401865
[1] Rust could work as a case study here: how many places require `unsafe`?