3 ms·
Honestly, the Arc<Mutex<T>> approach is the right one here. We need to hand out shared references, and that’s what that is. Otherwise there’s a ton of bookkeepi
by lilyball 5y ago
Honestly, the Arc<Mutex<T>> approach is the right one here. We need to hand out shared references, and that’s what that is. Otherwise there’s a ton of bookkeeping, and throwing exceptions in code that could otherwise reasonably work.
This approach assumes of course that there are no reference cycles in the graph. If there are, you’ll need some way to clean them up if Weak isn’t sufficient.
Alternatively, is there a way to ask Python to allocate memory for you, which is then subject to Python’s GC? If so, you could make a smart pointer type for this and use that everywhere. Though you’ll still need to figure out how thread safety works. So this really would only be for handling reference cycles.