3 ms·
Sorry but I don't quite get it. It seems that generational reference is a way of memory tagging that avoids users from use-after-free, while reference counting
by pca006132 4y ago
Sorry but I don't quite get it. It seems that generational reference is a way of memory tagging that avoids users from use-after-free, while reference counting is a way of tracking the number of references to an object and free it when it is no longer reachable.
It seems to me that generational reference isn't replacing reference counting as it is not deciding when to free the object? Perhaps this is more like a weak reference or something?
- azakai 4y agoThey are very different in those respects, correct. But I think the point here is that both are ways of achieving memory safety.
- pca006132 4y agoSo the non-owning references are kind of like weak reference but not implemented with Rc? I guess I now understand its purpose. Wondering how does this deal with multithread though. For example, the object A might be dropped in thread 1 (increments the generation number in thread 1) and accessed in thread 2 (reads the generation number). How do they guarantee an error in this case without using atomics? (although this might not be a valid question because you can't really say A is dropped before thread 2 accessing A without some sort of synchronization...)