Hacker News new | ask | show | jobs
by mamcx 2692 days ago
But how many times the problem truly happened? Is in my experience so rare that the experience is alike with a GC.
3 comments

It depends on your domain. Any data structure that has links in both directions becomes a pain, and it's pretty common to have trees like that. It's usually solved by having parents own the children but not vice versa, but then you run into cases where you want the whole thing to live so long as someone holds an owning reference to a child.
Agree. Is similar on rust, where circular links are also hard to do. Easy graphs is a killer feature of a GC.

But also, is a localized problem. I have more issues with obj-c in the past, some ergonomic of swift make it even rarer.

However, certainly suck for the ones that hit this!. I'm building a relational lang in rust and damm, I miss a GC!

Many people in the Rust community use some sort of ECS in cases where something like a GC is needed. The whole point of ECS is that they work a lot like an ordinary GC runtime or an in-memory database, the underlying representation ensures that the system knows about all the "entities" that it needs to, and can reliably trace linkages between them. It might be easier to just use Go in cases where tracing GC is needed, though.
I've only heard of using ECS for games. I'll have to look into them more closely.
When would you want the graph to exist due to some leaf more being retained but you wouldn’t know about it enough to maintain a ref to the root mode?
In a language with tracing GC, you'd use a strong reference in both directions, so anybody who holds the child can always walk their way to the root (if you expose those references). Without such GC, you basically have to pass the root around, because it's what's holding all those children alive.
- Doubly linked lists.

- Cocoa delegates that keep references to some parent of the objects that they're delegates of.

- Some event listeners (in the same way as delegates).

I wouldn't say it's "rare". It popped up pretty often for me when I was writing Objective C.

What’s not solved with weak refs?
What's not solved with manual memory management? The point is not that you can't solve it, the point is that reference counting isn't the whole solution for garbage collection unlike a tracing gc for instance.
Weak reference counting is still reference counting.
It can always be solved with weak references.
Only if you know that you haven't solved it already: https://news.ycombinator.com/item?id=19093677
Alike a tracing GC..,.