by andai · 2w ago · 0 comments
But it really depends on what you're doing. You can use the wrong tool for a job, but you can also use the right tool. It depends on the job.
And at least with GC, you are guaranteed to surrender the possibility of double-free and use-after-free.
That is a False Dichotomy
> GC is literally surrendering control.
it would seem that no GC is in the other direction, literally not surrendering control.
Manual memory management is not the only alternative to GC; RAII & smart pointers require, for the overwhelming majority of uses, no more thought than C#'s `new Foo` does, and don't require the concerns about manually free, use-afte-free, etc. that come with "manual memory".
I'm not saying manage memory manually. You can switch to a language that is reference counted. Then at least that abstraction guarantees deterministic deallocation.
That comes with another set of trade-offs such as having to pay attention to atomic reference counts, making sure there's no cycles, maybe even treating some graphs as arenas to avoid chained deallocations, but the abstraction itself is designed to be deterministic and is more easily controlled.
One does not have to live with the tradeoffs that C#'s default GC makes. One just needs to understand how the GC works and how it is controlled.
I love .NET and its been my main environment for about as long as I've been making software, but the small things like that were part of the initial motivation for me to make my own language. .NET is exactly what I want for most tasks, it offers great interop with native code and good tools for low level code and manual memory management, but you never really get control of the process like you have in something like C/++ or Rust