Comment by kev009

2 hours ago

Even things built directly on underlying malloc and free typically have some form of "garbage collection" in the malloc implementation for efficiency and performance (geometric sizing, thread caching, etc).

It's best to think about lifetimes and lifecycles where possible. Immutability where sensible and things like pool allocation are examples of this.

GC languages can result in quite pessimistic code because they encourage people to NOT think about what is going on. But people have also built functional HFT engines on things like the JVM by thinking about lifetimes and lifecycles.

Ultimately, the entire problem of deallocation in general is a continuum, not a binary, and I tend to find it hard to take anyone seriously who is vigorously arguing about how awful GC is if they don't understand that and indicate some understanding of the concept. The closest you can get to real "manual" memory management on a modern system is to use nothing but arena allocations, and if you really want "manual" memory management, you need to allocate some small fixed number of arenas, because if you're constantly allocating and deallocating them that is itself probably an automated process that could go wrong, at least in theory. Malloc/free or new/delete isn't really "manual memory management".

The wide variety of options and tradeoffs, with fewer clear lines in the sand than most people seem to think, is already enough to call it a "continuum" but what really finishes the job is that they're all mixable and matchable. Something like Zig makes that really obvious, but most static languages have at least some sort of ability to mix in multiple strategies. There's nothing wrong with a C++ program that uses new & delete, and also uses arenas for some things, and also uses garbage collection for some things, and also has an integrated scripting language like Lua with its own memory strategies. Such programs are not that uncommon... that describes modern games nowadays, the supposed canonical case where you "can't afford GC". But it can... it just fences it in to a particular domain where it fits.