3 ms·
> or let the garbage collector do it (in which case it's not Rust anymore). Arc<T> is still Rust. Not ideal, but very much still Rust. I wouldn't be surprised
by 15155 4y ago
> or let the garbage collector do it (in which case it's not Rust anymore).
Arc<T> is still Rust. Not ideal, but very much still Rust. I wouldn't be surprised if despite wrapping absolutely every object in Arc, Rust still were to perform better than most high-level languages at whatever given task.
- tialaramex 4y agoArc isn't a garbage collector though, Arc is just reference counting. You could write this by hand. Languages which have a GC may in some cases also do reference counting to reduce the load on the GC, but they need the GC because reference counting doesn't collect cycles. It's trivial to make a cycle, then destroy all references to it - and in Rust that cycle lives forever, it can't be destroyed because each part of it has references from the rest. With a GC this gets collected, eventually, exactly when will vary which is why in the GC language destructors aren't as useful for resource clean-up as they are in languages like C++ or Rust.