upvote
Garbage collection is a feature but it's also a trade-off, like most things in engineering. IMO it's a worthwhile trade-off more often than a lot of people think (though a lot of people don't think enough about it). But there's also times that it's not worthwhile, and we shouldn't pretend otherwise.
reply
GC is literally surrendering control.

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.

reply
It's only surrendered control if you refuse to understand it and how to control it.
reply
The (Tracing) Garbage Collector abstraction isn't really designed to be controlled though. You can understand the implementation and write code against that, but at that point, why not switch to something that you can genuinely control?

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.

reply
Exactly. You have a shocking amount of control over the GC if you bother to learn. Surrendering control is a choice the programmer makes by not understanding their tools.
reply
There's still limits on that control.
reply
You'll need to be a lot more specific, because C# offers you a lot of control. You can, for example, disable GC and run it manually at runtime. You can exempt objects from GC. You can exempt objects from relocation. You have pointers and unsafe contexts. Frankly I can't think of anything you'd want to do with GC that isn't offered already.

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.

reply
Indeed - even Unreal Engine uses GC for all its internal object management. It's not a language level thing, more a runtime entity thing, but it is there. It simplifies object lifetime management quite a bit.

To be fair, it is also probably the number one cause of long hitches in poorly optimized UE games, and also the main contributor to class of use-after-free bugs (persisted native pointers and references to objects that weren't properly added to the object graph, though goes away with proper usage of weak object pointers and the like) so it is very much a double-edged-sword.

reply
I think some devs have painful memories of early GCs, compounded by the qualities associated with “corporate” codebases of the time. I would imagine younger programmers are writing more managed code than C and skew towards having no complaints about GCs.

Agreed that it’s no longer a bottleneck for games; profile—and-optimize approaches are very effective and the tooling has never been better.

reply
Exactly. The problem People have with GC is not garbage collection per se, it is garbage collection pressure. The solution to which isn’t doing away with the GC, it is managing and controlling allocation.
reply
Arguably without GC C# becomes a different language. But if you’re really comfortable with C# and can’t handle unexpected lag spikes I can see this being useful.
reply
Arenas, etc is GC done right.

Or rather GC done explicit.

You control when and where and how garbage gets collected in various buckets and disposed off.

Without the performance hit of fully automatic GC.

> Risking memory leaks is crazy when it's not something the customer is demanding.

Memory leaks have NEVER been a significant source of bugs.

Memory corruption has always been the problem (lack of memory safety, ie. operating in perpetual unsafe block), not the memory leaks.

Memory leaks are relatively trivial to track and account for in comparison.

reply
Generational moving GCs work much like arenas, and they work without the limitations of arenas and without the performance hit of malloc/free. That's not to say arenas aren't very efficient and useful, but few languages make them convenient and composable enough (Zig), and even then they need to be used with care.
reply
> and without the performance hit of malloc/free.

Arenas avoid most of the performance problems of malloc/free.

I think the bigger problem with arenas and manual management is memory lifetime is very hard to get right, particularly in the context of concurrent operations. It also cuts away algorithms you can do.

reply
> Arenas avoid most of the performance problems of malloc/free.

Sure, but they're not fully general, which is why you also need malloc/free for things that don't work well in arenas (or write the equivalent of malloc/free on top of arenas, which is what you need to do in Goose: https://github.com/aardappel/goose/blob/master/bench/kostya/...).

Also, arenas can be an even better fit for languages with good GCs than languages without a GC.

reply
[dead]
reply