Hacker News new | past | comments | ask | show | jobs | submit
The GC is a feature. Not a bug to be eliminated.

GC is not surrendering control. That seems to be HN's #1 bug bear. The sensation that someone or something is taking control away from you. The proper way to frame this is that you can actually focus on the original problem you set out to solve. Risking memory leaks is crazy when it's not something the customer is demanding. Even in gaming I think the GC is fine. There are ways to spread the impact across frames and bound the amount of time spent collecting.

If your clever scheme wouldn't work with a GC-managed heap, it probably won't work with one managed by hand either.

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.
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.

It's only surrendered control if you refuse to understand it and how to control it.
loading story #50593021
loading story #50591492
loading story #50592592
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.

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.

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.
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.
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.

loading story #50593334
loading story #50592522