Closed dragazo closed 7 months ago
I think adding reference counting is a deal breaker, sorry.
It might be worth it to explore a general reference-counting-with-cycle-detection garbage collector design though? I think such a garbage collector wouldn't require branding for memory safety (but might end up requiring something similar for correctness?) and thus might fit situations where gc-arena is currently kind of annoying. I wonder if one exists already (for Rust, obviously)? I haven't looked very hard.
Anyway, gc-arena exists in the design space where you don't want reference counting, and I think you could (should) do an entirely different design for a collector with reference counting.
This is just a wild feature request that would be useful for a project I'm working on.
Would it be possible to support something like
Rc::into_inner
forGc<T>
to get the value out of aGc<T>
if it's a unique pointer to it? I realize this would require reference counting forGc<T>
, which would breakCopy
(and maybe be a total deal breaker?), but we'd still get to keepClone
and it would only cost an integer increment (and a decrement inDrop
).Also, by doing reference counting, in the future we could possibly do eager collection of objects whose reference count falls to zero so that the mark-and-sweep collector has less work to do for use cases where cycles are possible but somewhat rare (as they are in my case). Although that's a totally separate extra feature and there might be some nuances of the safety proof that would forbid this anyway - I'm just throwing the idea out there lol
If something like this does get added, other useful things might be
Rc::get_mut
andRc::make_mut
.