4 ms·
I mostly agree with your point on RAII. But I don't think OP was advocating RAII. The typical argument for GC is that it is less error-prone than even RAII. A
by norswap 7y ago
I mostly agree with your point on RAII.
But I don't think OP was advocating RAII.
The typical argument for GC is that it is less error-prone than even RAII. And I agree with that point. It's a trade-off on which you have to decide on. I think the tiny perf penalty is often worth it.
You can still retain stale data under a GC, but real leaks (unreachable allocated memory) are precluded — which is usually considered (not unreasonably) to be the more common and serious problem.
I think GC is a sane default because it's less error prone, and god knows the average developer will make enough errors as it is. I'd trust myself with manual memory management, but not a random group of developers I don't know. What about you?
- nine_k 7y agoYou can of course introduce a space leak in a honest GC environment. Make a linked list, and keep adding items to it while keeping its head referenced. Of course you do it by mistake: you kept two references, the main and the auxiliary, and the main reference is duly gone. This is why weak references were invented.