News for hackers. Stuff that matters.
Re:Ask HN: Why do langs with alleged “automatic memory manag... by Someone on Thursday July 18, 2019 @08:30PM (#20475277)
GC can do that, for a loose definition of when they’re inaccessible (it will do it when, but not as soon as)

Reference counting almost gives you as soon as, but it has trouble handling circular references. That is fixable, but not, AFAIK, in a way that’s both reasonably performance, frees resources as soon as they become unreachable, and isn’t too restricting.

Re:Ask HN: Why do langs with alleged “automatic memory manag... by bjourne on Saturday July 20, 2019 @12:54AM (#20484247)
What fix are you referring to? The ones I know of are algorithms for detecting when the object graph becomes disconnected. Unfortunately that turns out to be very hard in practice and you often have to scan a large portion of the heap. So it doesn't offer any major advantage over reference counting + mark & sweep gc. Which is kind of the worst of both worlds. :/ Ref counting overhead + potentially long gc pause times.
Re:Ask HN: Why do langs with alleged “automatic memory manag... by Someone on Saturday July 20, 2019 @01:27PM (#20487092)
Ones that are either not reasonably performant, don’t free resources as soon as they become unreachable, or are too restricting.

The fix you refer to is one, but it falls under ‘not reasonably performant’.

One could also make it illegal to have cycles (easy way to do that: make it illegal to update any references). For many, many, that will fall under ‘too restricting’, though.

Alternatively, allow updates to references, but give every allocated object a ‘bit’ that indicates whether, from it, a reference can be reached that contains such an updated reference that points to an object created later (maintaining that property is doable, but may not be ‘reasonably performant’)

You can use that later: when the reference count of an object goes to zero, and the object has a reference to an object O with that bit set, check whether the graph reachable from O can be reached from elsewhere. Again, that’s doable, but likely not performant.

It somewhat depends on how common circular references are in real world code, though. I’m not aware of any papers researching that.