Generational reference counting in rust

Memory management in vale language quite interesting.

Is rust lang currently have this features or in future

I don't think so. There is a new borrow checker on the way though.

There's this crate and probably others. I'm unaware of any push at the std or language levels.

1 Like

This article goes in depth:

It seems like this can be implemented as a library in Rust. Vale proposes using an optimizer to eliminate redundant checks. That isn't so necessary for Rust, because Rust libraries can use borrowing to give zero-cost access to objects (beyond one check when converting a generational reference to a borrowed reference). For the same reason Rust's Rc isn't as expensive as reference counting in other languages that need to touch refcount every time object is passed.

Generational references are used for example in the Rust Bevy engine's ECS.

The generational references in Vale are safe from use-after-free vulnerabilities, but unlike borrowing, they don't guarantee correctness. They can be left dangling pointing to a destroyed object (a previous generation). In this sense their semantics are similar to Rust's rc::Weak.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.