2 ms·
It doesn't leave anything relevant out. Java pioneered this garbage collection stuff because you had cycles of references. You don't need to have cycles. WeakR
by EGreg 2mo ago
It doesn't leave anything relevant out.
Java pioneered this garbage collection stuff because you had cycles of references. You don't need to have cycles. WeakRef is a much better thing now. All you need is reference counting, and you don't need any garbage collection at all. When the reference count reaches 0, you destroy the object and free up its memory. It's far more predictable than GC, too.
And GC isn't "the fastest" to free objects, it has to walk a graph. The fastest is actually arena allocation and then just dropping the whole thing. But that's exactly what owning an entire container of objects can do. If you have a doubly linked list, for example, A[n] -> A[n+1] but also A[n+1] -> A[n] but neither of those should be a strong reference to prevent reclaiming. Instead, the container of that doubly linked list should be the one having a strong reference to its items.
- thomashabets2 2mo agoI understood your first comment without expanding on it like this. You also don't need to explain what reference counting is. > GC isn't "the fastest" to free objects, it has to walk a graph. No, you don't inherently need to. And what I said is that it's super duper fast to produce garbage. I did not say that actually freeing the underlying memory, or any other cleanup, was fast. I'm not even arguing for GCs, here. I even think GC languages tend to become tech debt generators, as garbage is not addressed until it's a really complex problem with no good solutions.
- pjmlp 2mo agoSame can be said for bad algorithms and data structures, it isn't hard to make slow C when one doesn't know their stuff.
- pjmlp 2mo agoLisp pionered GC, and all its flavours, followed by CLU, Smalltalk, Cedar, BASIC and all its flavours, Modula-2+, Modula-3, Oberon, Oberon-2, Component Pascal, xBase/Clipper, Standard ML, Caml Light, Objective Caml (now OCaml), Miranda, Haskell,... Long before Java was even an idea.